X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=reader.cc;h=3ccfb7144bae80159e5172977dd3e9f475a55de9;hb=8987976196a50e3e9639879990c7473610ff5369;hp=46a0b812e7334485a6d22b1add42c62b4eca787a;hpb=121a58d72f3b5e537007072f93397f6e6661fb90;p=odcread.git diff --git a/reader.cc b/reader.cc index 46a0b81..3ccfb71 100644 --- a/reader.cc +++ b/reader.cc @@ -14,6 +14,12 @@ SHORTCHAR Reader::readSChar() { return out; } +BYTE Reader::readByte() { + BYTE out; + d_rider.read((char*)&out, 1); + return out; +} + INTEGER Reader::readInt() { char *buf = new char[4]; d_rider.read(buf, 4); @@ -32,17 +38,30 @@ void Reader::readSString(SHORTCHAR *out) { } } +INTEGER Reader::readVersion(INTEGER min, INTEGER max) { + INTEGER version = readByte(); + //if (version < min || version > max) { + // rd.TurnIntoAlien(alienVersion) + //} + return version; +} + Store* Reader::readStore() { SHORTCHAR kind = readSChar(); if (kind == Store::NIL) { + std::cout << "NIL STORE" << std::endl; return readNilStore(); } else if (kind == Store::LINK) { + std::cout << "LINK STORE" << std::endl; return readLinkStore(); } else if (kind == Store::NEWLINK) { + std::cout << "NEWLINK STORE" << std::endl; return readNewLinkStore(); } else if (kind == Store::STORE) { + std::cout << "STORE STORE" << std::endl; return readStoreOrElemStore(false); } else if (kind == Store::ELEM) { + std::cout << "ELEM STORE" << std::endl; return readStoreOrElemStore(true); } else { throw 20; @@ -80,12 +99,9 @@ Store *Reader::readNewLinkStore() { Store *Reader::readStoreOrElemStore(bool isElem) { INTEGER id = isElem ? d_elemList.size() : d_storeList.size(); - SHORTCHAR** path = newTypePath(); - readPath(path); - for (int i = 0; path[i] != 0; ++i) { - std::cout << path[i] << std::endl; - } - SHORTCHAR* type = path[0]; + TypePath path = readPath(); + std::cout << path.toString() << std::endl; + const std::string &type = path[0]; INTEGER comment = readInt(); std::streampos pos1 = d_rider.tellg(); std::streamoff next = readInt(); @@ -116,15 +132,17 @@ Store *Reader::readStoreOrElemStore(bool isElem) { // ASSERT(downPos < rd.st.end, 105) // END; - void *t = 0; // FIXME type lookup here + const TypeProxyBase *t = TypeRegister::getInstance().get(type); // FIXME type lookup here + Store *x = 0; if (t != 0) { + x = t->newInstance(id); + x->internalize(*this); // x := NewStore(t); x.isElem := kind = elem } else { // rd.cause := thisTypeRes; AlienTypeReport(rd.cause, type); // x := NIL } - Store *x = 0; if (x != 0) { // IF READING SUCCEEDS, INSERT MORE CHECKS HERE } else { // rd.SetPos(pos); @@ -232,66 +250,52 @@ void Reader::internalizeAlien(Alien *alien, std::streampos down, std::streampos } } -void Reader::readPath(SHORTCHAR **path) { +std::string &Reader::fixTypeName(std::string &name) { + size_t pos = name.size() - 4; + if (pos > 0 && name.substr(pos, 4).compare("Desc") == 0) { + return name.replace(pos, 4, "^"); + } + return name; +} + +TypePath Reader::readPath() { + TypePath path; SHORTCHAR kind = readSChar(); + SHORTCHAR *buf = new SHORTCHAR[64]; // TypeName has a maximum of length 64 (including terminator). int i; for (i = 0; kind == Store::NEWEXT; ++i) { - readSString(path[i]); + readSString(buf); + std::string name(buf); + path.push_back(fixTypeName(name)); addPathComponent(i == 0, path[i]); // IF path[i] # elemTName THEN INC(i) END; kind = readSChar(); } if (kind == Store::NEWBASE) { - readSString(path[i]); + readSString(buf); + std::string name(buf); + path.push_back(fixTypeName(name)); addPathComponent(i == 0, path[i]); ++i; } else if (kind == Store::OLDTYPE) { int id = readInt(); - d_typeList[d_typeList.size() - 1]->baseId = id; -// REPEAT -// GetThisType(rd.tDict, id, path[i]); id := ThisBaseId(rd.tDict, id); + if (i > 0) { + d_typeList[d_typeList.size() - 1]->baseId = id; + } + while (id != -1) { + path.push_back(d_typeList[id]->name); + id = d_typeList[id]->baseId; // IF path[i] # elemTName THEN INC(i) END -// UNTIL id = -1 + ++i; + } } else { throw 100; } - path[i] = 0; + return path; } -// PROCEDURE ReadPath (VAR rd: Reader; VAR path: TypePath); -// VAR h: TypeDict; id, extId: INTEGER; i: INTEGER; kind: SHORTCHAR; -// -// PROCEDURE AddPathComp (VAR rd: Reader); -// BEGIN -// IF h # NIL THEN AddBaseId(h, extId, rd.nextTypeId) END; -// AddType(rd.tDict, rd.tHead, rd.nextTypeId, path[i]); -// h := rd.tHead; extId := rd.nextTypeId -// END AddPathComp; -// -// BEGIN -// h := NIL; i := 0; rd.ReadSChar(kind); -// WHILE kind = newExt DO -// rd.ReadXString(path[i]); -// AddPathComp(rd); INC(rd.nextTypeId); -// IF path[i] # elemTName THEN INC(i) END; -// rd.ReadSChar(kind) -// END; -// IF kind = newBase THEN -// rd.ReadXString(path[i]); -// AddPathComp(rd); INC(rd.nextTypeId); INC(i) -// ELSE -// ASSERT(kind = oldType, 100); -// rd.ReadInt(id); -// IF h # NIL THEN AddBaseId(h, extId, id) END; -// REPEAT -// GetThisType(rd.tDict, id, path[i]); id := ThisBaseId(rd.tDict, id); -// IF path[i] # elemTName THEN INC(i) END -// UNTIL id = -1 -// END; -// path[i] := "" -// END ReadPath; -void Reader::addPathComponent(bool first, SHORTCHAR *typeName) { +void Reader::addPathComponent(bool first, const std::string &typeName) { int next = d_typeList.size(); int curr = next - 1; if (!first) {