X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=reader.cc;h=ffca53deacab5f2a2cfa280b6107ee0e5b23371a;hb=149d7ca4cf84c3c9b7eb55b02d6b152fb00894bf;hp=1f60ce8fe31041fda6ebb15c5f740ed5022bf474;hpb=63b438eb6e7c0e06bf37614c5de3c03f25301af5;p=odcread.git diff --git a/reader.cc b/reader.cc index 1f60ce8..ffca53d 100644 --- a/reader.cc +++ b/reader.cc @@ -24,16 +24,20 @@ CHAR Reader::readLChar() { char *bufPtr = (char *)&buf; d_rider.read(bufPtr, 2); if (isLittleEndian()) { - return buf; + return buf - 0x8000; } else { CHAR out; char *outPtr = (char *)&out; outPtr[0] = bufPtr[1]; outPtr[1] = bufPtr[0]; - return out; + return out - 0x8000; } } void Reader::readLChar(CHAR *buf, size_t len) { + for (int i = 0; i < len; ++i) { + buf[i] = readLChar(); + } + /* char *bufPtr = (char *)buf; int len2 = len * 2; d_rider.read(bufPtr, len2); @@ -45,6 +49,7 @@ void Reader::readLChar(CHAR *buf, size_t len) { bufPtr[i + 1] = tmp; } } + */ } BYTE Reader::readByte() { @@ -53,6 +58,20 @@ BYTE Reader::readByte() { return out; } +SHORTINT Reader::readSInt() { + SHORTINT buf; + char *bufPtr = (char*)&buf; + d_rider.read(bufPtr, 2); + if (isLittleEndian()) { + return buf; + } else { + SHORTINT out; + char *outPtr = (char *)&out; + outPtr[0] = bufPtr[1]; outPtr[1] = bufPtr[0]; + return out; + } +} + INTEGER Reader::readInt() { INTEGER buf; char *bufPtr = (char*)&buf; @@ -95,22 +114,22 @@ INTEGER Reader::readVersion(INTEGER min, INTEGER max) { Store* Reader::readStore() { SHORTCHAR kind = readSChar(); if (kind == Store::NIL) { - std::cout << "NIL STORE" << std::endl; + //std::cout << "NIL STORE" << std::endl; return readNilStore(); } else if (kind == Store::LINK) { - std::cout << "LINK STORE" << std::endl; + //std::cout << "LINK STORE" << std::endl; return readLinkStore(); } else if (kind == Store::NEWLINK) { - std::cout << "NEWLINK STORE" << std::endl; + //std::cout << "NEWLINK STORE" << std::endl; return readNewLinkStore(); } else if (kind == Store::STORE) { - std::cout << "STORE STORE" << std::endl; + //std::cout << "STORE STORE" << std::endl; return readStoreOrElemStore(false); } else if (kind == Store::ELEM) { - std::cout << "ELEM STORE" << std::endl; + //std::cout << "ELEM STORE" << std::endl; return readStoreOrElemStore(true); } else { - std::cout << std::hex << (unsigned int)kind << std::endl; + //std::cout << std::hex << (unsigned int)kind << std::endl; throw 20; } } @@ -119,7 +138,16 @@ Store* Reader::readStore() { // len, pos, pos1, id, comment, next, down, downPos, nextTypeId, nextElemId, nextStoreId: INTEGER; // kind: SHORTCHAR; path: TypePath; type: TypeName; // save: ReaderState; + Store *Reader::readNilStore() { + INTEGER comment = readInt(); + std::streamoff next = readInt(); + d_state->end = d_rider.tellg(); + if (next > 0 || (next == 0 && comment % 2 == 1)) { + d_state->next = d_state->end + next; + } else { + d_state->next = 0; + } return 0; } // IF kind = nil THEN @@ -127,16 +155,18 @@ Store *Reader::readNilStore() { // rd.st.end := rd.Pos(); // IF (next > 0) OR ((next = 0) & ODD(comment)) THEN rd.st.next := rd.st.end + next ELSE rd.st.next := 0 END; // x := NIL + Store *Reader::readLinkStore() { - return 0; + throw "Reader::readLinkStore() not implemented"; } // ELSIF kind = link THEN // rd.ReadInt(id); rd.ReadInt(comment); rd.ReadInt(next); // rd.st.end := rd.Pos(); // IF (next > 0) OR ((next = 0) & ODD(comment)) THEN rd.st.next := rd.st.end + next ELSE rd.st.next := 0 END; // x := ThisStore(rd.eDict, id) + Store *Reader::readNewLinkStore() { - return 0; + throw "Reader::readNewLinkStore() not implemented"; } // ELSIF kind = newlink THEN // rd.ReadInt(id); rd.ReadInt(comment); rd.ReadInt(next); @@ -147,7 +177,7 @@ Store *Reader::readNewLinkStore() { Store *Reader::readStoreOrElemStore(bool isElem) { INTEGER id = isElem ? d_elemList.size() : d_storeList.size(); TypePath path = readPath(); - std::cout << path.toString() << std::endl; + //std::cout << path.toString() << std::endl; const std::string &type = path[0]; INTEGER comment = readInt(); std::streampos pos1 = d_rider.tellg(); @@ -210,7 +240,6 @@ Store *Reader::readStoreOrElemStore(bool isElem) { d_store = x; } else { // join(d_store, x) - std::cout << "Man, should have written join(.,.)" << std::endl; } if (isElem) { d_elemList.push_back(x); @@ -225,7 +254,6 @@ Store *Reader::readStoreOrElemStore(bool isElem) { d_store = alien; } else { // join(d_store, alien) - std::cout << "Man, should have written join(.,.)" << std::endl; } if (isElem) { d_elemList.push_back(alien); @@ -254,14 +282,12 @@ void Reader::internalizeAlien(Alien *alien, std::streampos down, std::streampos std::streampos next = down != 0 ? down : end; while (d_rider.tellg() < end) { if (d_rider.tellg() < next) { // for some reason, this means its a piece (unstructured) - std::cout << "Alien Piece" << std::endl; size_t len = next - d_rider.tellg(); char *buf = new char[len]; d_rider.read(buf, len); AlienComponent *comp = new AlienPiece(buf, len); alien->getComponents().push_back(comp); } else { // that means we've got a store - std::cout << "Alien Store" << std::endl; d_rider.seekg(next); AlienComponent *comp = new AlienPart(readStore()); alien->getComponents().push_back(comp);