unsigned long getLength(const RVNGInputStreamPtr &input) { checkStream(input); const long begin = input->tell(); if (0 > begin) throw SeekFailedException(); long end = begin; if (0 == input->seek(0, librevenge::RVNG_SEEK_END)) end = input->tell(); else { // RVNG_SEEK_END does not work. Use the harder way. while (!input->isEnd()) { readU8(input); ++end; } } seek(input, begin); assert(begin <= end); return static_cast<unsigned long>(end - begin); }
bool LotusParser::readZones() { RVNGInputStreamPtr input = getInput(); // reset data m_styleManager->cleanState(); m_graphParser->cleanState(); m_spreadsheetParser->cleanState(); input->seek(0, librevenge::RVNG_SEEK_SET); bool mainDataRead=false; // data, format and ? for (int wh=0; wh<2; ++wh) { if (input->isEnd()) break; while (readZone()) ; // // look for ending // long pos = input->tell(); if (!checkFilePosition(pos+4)) break; int type = (int) libwps::readU16(input); // 1 int length = (int) libwps::readU16(input); if (type==1 && length==0) { ascii().addPos(pos); ascii().addNote("Entries(EOF)"); if (!mainDataRead) mainDataRead=m_state->m_inMainContentBlock; // end of block, look for other blocks continue; } input->seek(pos, librevenge::RVNG_SEEK_SET); break; } while (!input->isEnd()) { long pos=input->tell(); int id = (int) libwps::readU8(input); int type = (int) libwps::readU8(input); long sz = (long) libwps::readU16(input); if ((type>0x2a) || sz<0 || !checkFilePosition(pos+4+sz)) { input->seek(pos, librevenge::RVNG_SEEK_SET); break; } libwps::DebugStream f; f << "Entries(UnknZon" << std::hex << id << "):"; ascii().addPos(pos); ascii().addNote(f.str().c_str()); input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); } if (!input->isEnd()) { ascii().addPos(input->tell()); ascii().addNote("Entries(Unknown)"); } return mainDataRead || m_spreadsheetParser->hasSomeSpreadsheetData(); }