X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=reader.cc;h=21cef1dd1882ec8fcdda0033f05821e6f67a538c;hb=a22f7e2fc867c7bab8488f2d544cea54721ed63c;hp=f53e30a8e896035d8a769d2de4cf10b27c9e8d33;hpb=98bcd76b4c284676f55d754879dee9bda1898924;p=odcread.git diff --git a/reader.cc b/reader.cc index f53e30a..21cef1d 100644 --- a/reader.cc +++ b/reader.cc @@ -53,6 +53,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 +109,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; } } @@ -155,7 +169,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(); @@ -218,7 +232,7 @@ Store *Reader::readStoreOrElemStore(bool isElem) { d_store = x; } else { // join(d_store, x) - std::cout << "Man, should have written join(.,.)" << std::endl; + //std::cout << "Man, should have written join(.,.)" << std::endl; } if (isElem) { d_elemList.push_back(x); @@ -233,7 +247,7 @@ Store *Reader::readStoreOrElemStore(bool isElem) { d_store = alien; } else { // join(d_store, alien) - std::cout << "Man, should have written join(.,.)" << std::endl; + //std::cout << "Man, should have written join(.,.)" << std::endl; } if (isElem) { d_elemList.push_back(alien); @@ -262,14 +276,14 @@ 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; + //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; + //std::cout << "Alien Store" << std::endl; d_rider.seekg(next); AlienComponent *comp = new AlienPart(readStore()); alien->getComponents().push_back(comp);