X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=reader.h;h=136fb4748cd45f9e0f5595f13e02f1e72b708339;hb=e2fd5debfd8b94a6ec77a514962851594f0690f0;hp=cfd4fc53194f1242de4890a369e5765bc086bce5;hpb=4618e826a4ebe5e60e1d2c419fca7da71657bf9b;p=odcread.git diff --git a/reader.h b/reader.h index cfd4fc5..136fb47 100644 --- a/reader.h +++ b/reader.h @@ -2,12 +2,21 @@ #define _READER_H_ #include +#include #include #include +#include namespace odc { +struct TypeEntry { + const std::string name; + INTEGER baseId; + + TypeEntry(const std::string &typeName) : name(typeName), baseId(-1) {} +}; + /** * TYPE Reader * Reader for Component Pascal values like integers, reals, or sets. A reader contains a Files.Reader, to which it forwards most operations. @@ -16,6 +25,9 @@ namespace odc { */ class Reader { private: + static const unsigned int TYPENOTFOUND = 1; + static const unsigned int ALIENVERSION = 2; + /* * rider-: Files.Reader * The file rider which links a Reader to a file. @@ -24,7 +36,7 @@ private: /* * cancelled-: BOOLEAN valid during a Store.Internalize call - * Tells whether the currently executing Internalize has been called by ReadVersion or TurnIntoAlien. + * Tells whether the currently executing Internalize has been cancelled by ReadVersion or TurnIntoAlien. */ bool d_cancelled; @@ -34,8 +46,29 @@ private: */ bool d_readAlien; - INTEGER d_nextElemId; - INTEGER d_nextStoreId; + /** + * Cause of current read being alien. + */ + unsigned int d_cause; + + std::vector d_typeList; + + std::vector d_elemList; // FIXME: WTH, why are these different? + std::vector d_storeList; + + Store *d_store; + + struct ReaderState { + /** + * Position of the next store in the current level + */ + std::streampos next; + /** + * Position just after the last read store + */ + std::streampos end; + }; + ReaderState *d_state; public: /** @@ -98,23 +131,32 @@ private: * 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. - * + */ + /** * 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 * Reads a very short integer (-128..127). - * + */ + BYTE readByte(); + /** * PROCEDURE (VAR rd: Reader) ReadSInt (OUT x: SHORTINT) * NEW * Reads a short integer (-32768..32767). - * + */ + SHORTINT readSInt(); + /** * PROCEDURE (VAR rd: Reader) ReadXInt (OUT x: INTEGER) * NEW * Same as ReadSInt, but has an INTEGER-type parameter. @@ -148,19 +190,24 @@ private: * PROCEDURE (VAR rd: Reader) ReadSet (OUT x: SET) * NEW * Reads a set (32 elements). - * + */ + /** * PROCEDURE (VAR rd: Reader) ReadSString (OUT x: ARRAY OF SHORTCHAR) * NEW * Reads a 0X-terminated short string. * * Pre * invalid index LEN(x) > Length(string) - * + */ + void readSString(SHORTCHAR *out); + /** * PROCEDURE (VAR rd: Reader) ReadXString (OUT x: ARRAY OF CHAR) * NEW * Same as ReadSString, but has a string-type parameter. * This procedure is provided to simplify migration from Release 1.2 to 1.3. - * + */ + //void readXString(CHAR *out); + /** * PROCEDURE (VAR rd: Reader) ReadString (OUT x: ARRAY OF CHAR) * NEW * Reads a 0X-terminated string. @@ -210,7 +257,9 @@ private: * rd.cause = alienVersion * rd.cancelled * rd.readAlien - * + */ + INTEGER readVersion(INTEGER min, INTEGER max); + /* * PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: INTEGER) * NEW * A store which is currently being internalized can turn itself into an alien, e.g., if it has read a component store which is an alien. @@ -218,29 +267,23 @@ private: * Pre * 20 cause > 0 */ + void turnIntoAlien(int cause); + + bool isCancelled(); private: Store *readStoreOrElemStore(bool isElem); Store *readNilStore(); Store *readLinkStore(); Store *readNewLinkStore(); + void internalizeAlien(Alien *alien, std::streampos down, std::streampos end); - /* - TypeName* = ARRAY 64 OF CHAR; - TypePath* = ARRAY 16 OF TypeName; - OpName* = ARRAY 32 OF CHAR; - */ - inline CHAR *newTypeName() { - return new CHAR[64]; - } - inline CHAR **newTypePath() { - CHAR **out = new CHAR*[16]; - for (int i = 0; i < 16; ++i) { - out[i] = newTypeName(); - } - return out; - } - void readPath(CHAR **path); + std::string &fixTypeName(std::string &name); + TypePath readPath(); + /** + * Add another component to the current path. If first==true, start a new path. + */ + void addPathComponent(bool first, const std::string &typeName); }; } // namespace odc