diff --git a/reader.cc b/reader.cc
index b027bd57299f3347c75b7c87d98c8dbcddc73c37..21cef1dd1882ec8fcdda0033f05821e6f67a538c 100644 (file)
--- a/reader.cc
+++ b/reader.cc
return out;
}
return out;
}
+void Reader::readSChar(SHORTCHAR *buf, size_t len) {
+ d_rider.read(buf, len);
+}
+
+CHAR Reader::readLChar() {
+ CHAR buf;
+ char *bufPtr = (char *)&buf;
+ d_rider.read(bufPtr, 2);
+ if (isLittleEndian()) {
+ return buf;
+ } else {
+ CHAR out;
+ char *outPtr = (char *)&out;
+ outPtr[0] = bufPtr[1]; outPtr[1] = bufPtr[0];
+ return out;
+ }
+}
+
+void Reader::readLChar(CHAR *buf, size_t len) {
+ char *bufPtr = (char *)buf;
+ int len2 = len * 2;
+ d_rider.read(bufPtr, len2);
+ if (isBigEndian()) {
+ char tmp;
+ for (int i = 0; i < len2; i += 2) {
+ tmp = bufPtr[i];
+ bufPtr[i] = bufPtr[i + 1];
+ bufPtr[i + 1] = tmp;
+ }
+ }
+}
+
BYTE Reader::readByte() {
BYTE out;
d_rider.read((char*)&out, 1);
return out;
}
BYTE Reader::readByte() {
BYTE out;
d_rider.read((char*)&out, 1);
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 Reader::readInt() {
- char *buf = new char[4];
- d_rider.read(buf, 4);
+ INTEGER buf;
+ char *bufPtr = (char*)&buf;
+ d_rider.read(bufPtr, 4);
if (isLittleEndian()) {
if (isLittleEndian()) {
- return *(INTEGER *)buf;
+ return buf;
} else {
} else {
- char *out = new char[4];
- out[0] = buf[3]; out[1] = buf[2]; out[2] = buf[1]; out[3] = buf[0];
- return *(INTEGER *)out;
+ INTEGER out;
+ char *outPtr = (char *)&out;
+ outPtr[0] = bufPtr[3]; outPtr[1] = bufPtr[2]; outPtr[2] = bufPtr[1]; outPtr[3] = bufPtr[0];
+ return out;
}
}
}
}
Store* Reader::readStore() {
SHORTCHAR kind = readSChar();
if (kind == Store::NIL) {
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) {
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) {
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) {
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) {
return readStoreOrElemStore(false);
} else if (kind == Store::ELEM) {
- std::cout << "ELEM STORE" << std::endl;
+ //std::cout << "ELEM STORE" << std::endl;
return readStoreOrElemStore(true);
} else {
return readStoreOrElemStore(true);
} else {
- std::cout << std::hex << (unsigned int)kind << std::endl;
+ //std::cout << std::hex << (unsigned int)kind << std::endl;
throw 20;
}
}
throw 20;
}
}
// kind: SHORTCHAR; path: TypePath; type: TypeName;
// save: ReaderState;
Store *Reader::readNilStore() {
// 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
return 0;
}
// IF kind = nil THEN
Store *Reader::readStoreOrElemStore(bool isElem) {
INTEGER id = isElem ? d_elemList.size() : d_storeList.size();
TypePath path = readPath();
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();
const std::string &type = path[0];
INTEGER comment = readInt();
std::streampos pos1 = d_rider.tellg();
d_store = x;
} else {
// join(d_store, x)
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);
}
if (isElem) {
d_elemList.push_back(x);
d_store = alien;
} else {
// join(d_store, alien)
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);
}
if (isElem) {
d_elemList.push_back(alien);
@@ -220,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::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
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);
d_rider.seekg(next);
AlienComponent *comp = new AlienPart(readStore());
alien->getComponents().push_back(comp);