summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b0fce2)
raw | patch | inline | side by side (parent: 9b0fce2)
author | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Wed, 10 Aug 2011 20:52:31 +0000 (21:52 +0100) | ||
committer | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Wed, 10 Aug 2011 20:52:31 +0000 (21:52 +0100) |
reader.cc | patch | blob | history | |
reader.h | patch | blob | history | |
textmodel.cc | patch | blob | history | |
textmodel.h | patch | blob | history |
diff --git a/reader.cc b/reader.cc
index b027bd57299f3347c75b7c87d98c8dbcddc73c37..1f60ce8fe31041fda6ebb15c5f740ed5022bf474 100644 (file)
--- a/reader.cc
+++ b/reader.cc
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);
}
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()) {
- return *(INTEGER *)buf;
+ return buf;
} 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;
}
}
diff --git a/reader.h b/reader.h
index b4f475ca725bceff119d4f2bd790171995d4bd56..21178f304e2ba32ee0d0ff86d6a74c39c8d2a028 100644 (file)
--- a/reader.h
+++ b/reader.h
* Reads a short character (00X..0FFX).
*/
SHORTCHAR readSChar();
+ void readSChar(SHORTCHAR *buf, size_t len);
/* PROCEDURE (VAR rd: Reader) ReadXChar (OUT x: CHAR)
* NEW
* Same as ReadSChar, but has a CHAR-type parameter.
* This procedure is provided to simplify migration from Release 1.2 to 1.3.
*/
- CHAR readXChar();
/**
* PROCEDURE (VAR rd: Reader) ReadChar (OUT x: CHAR)
* NEW
* Reads a character (0000X..0FFFFX).
*/
+ CHAR readLChar();
+ void readLChar(CHAR *buf, size_t len);
/**
* PROCEDURE (VAR rd: Reader) ReadByte (OUT x: BYTE)
* NEW
diff --git a/textmodel.cc b/textmodel.cc
index bc76a32798a9feff7848e7014bc6ca5ece906244..92ff862ade0662c199002db0ecf1b25106947596 100644 (file)
--- a/textmodel.cc
+++ b/textmodel.cc
#include <reader.h>
#include <vector>
+#include <assert.h>
namespace odc {
if (reader.isCancelled()) return;
std::vector<Store *> dict;
+ std::vector<TextPiece *> pieces;
INTEGER len = reader.readInt();
BYTE ano = reader.readByte();
std::cout << "len " << len << " ano " << (int)ano << std::endl;
+ int skip = 0;
while (ano != -1) {
if (ano == dict.size()) {
Store *attr = reader.readStore(); // readAttributes(); Stores.Join(t, attr)
INTEGER pieceLen = reader.readInt();
if (pieceLen > 0) { // shortchar piece
std::cout << "Found SChar piece" << std::endl;
+ pieces.push_back(new ShortPiece(pieceLen));
// NEW(sp); sp.len := len; sp.attr := attr;
// sp.file := rd.rider.Base(); sp.org := org; un := sp;
// INC(org, len) -- increment org by len ?
} else if (pieceLen < 0) { // longchar piece
std::cout << "Found LChar piece" << std::endl;
+ assert(pieceLen % 2 == 0);
+ pieces.push_back(new LongPiece(pieceLen / 2));
// len := -len; ASSERT(~ODD(len), 100);
// NEW(lp); lp.len := len DIV 2; lp.attr := attr;
// lp.file := rd.rider.Base(); lp.org := org; un := lp;
// rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view);
// v.view.InitContext(NewContext(v, t));
// un := v; INC(org) -- increment org by one?? WTH?
+ pieces.push_back(new ViewPiece());
+ ++skip;
}
ano = reader.readByte();
}
+ for (int i = 0; i < pieces.size(); ++i) {
+ pieces[i]->read(reader);
+ }
// rd.SetPos(org);
}
// PROCEDURE (t: StdModel) Internalize (VAR rd: Stores.Reader);
// END Internalize;
//
+TextPiece::TextPiece(size_t len): d_len(len) {}
+
+LongPiece::LongPiece(size_t len): TextPiece(len) {}
+
+void LongPiece::read(Reader &reader) {
+ CHAR *buf = new CHAR[d_len];
+ reader.readLChar(buf, d_len);
+ delete buf;
+}
+
+ShortPiece::ShortPiece(size_t len): TextPiece(len) {}
+
+void ShortPiece::read(Reader &reader) {
+ SHORTCHAR *buf = new SHORTCHAR[d_len + 1];
+ reader.readSChar(buf, d_len);
+ buf[d_len] = 0;
+ std::cout << "READING SHORT PIECE" << std::endl;
+ std::cout << std::string(buf) << std::endl;
+ delete buf;
+}
+
+ViewPiece::ViewPiece(): TextPiece(0) {}
+
+void ViewPiece::read(Reader &reader) {
+ reader.readByte();
+}
+
} // namespace odc
diff --git a/textmodel.h b/textmodel.h
index 13a3d56df9803caf546a0907117f9d21e79e84f5..93fa5b7aeba80aabbbddad13534b784484322f11 100644 (file)
--- a/textmodel.h
+++ b/textmodel.h
virtual void internalize(Reader &reader);
};
+ class TextPiece {
+ public:
+ const size_t d_len;
+ TextPiece(size_t len);
+ virtual void read(Reader &reader) = 0;
+ };
+
+ class LongPiece : public TextPiece {
+ public:
+ LongPiece(size_t len);
+ virtual void read(Reader &reader);
+ };
+
+ class ShortPiece : public TextPiece {
+ public:
+ ShortPiece(size_t len);
+ virtual void read(Reader &reader);
+ };
+
+ class ViewPiece : public TextPiece {
+ public:
+ ViewPiece();
+ virtual void read(Reader &reader);
+ };
+
class StdTextModel : public TextModel {
private:
static const std::string TYPENAME;