aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/parallaction/objects.cpp6
-rw-r--r--engines/parallaction/parser.cpp34
-rw-r--r--engines/parallaction/parser.h21
-rw-r--r--engines/parallaction/parser_br.cpp4
-rw-r--r--engines/parallaction/parser_ns.cpp40
5 files changed, 45 insertions, 60 deletions
diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp
index 1a36bcd5f7..20f7469457 100644
--- a/engines/parallaction/objects.cpp
+++ b/engines/parallaction/objects.cpp
@@ -399,10 +399,12 @@ Table* createTableFromStream(uint32 size, Common::SeekableReadStream &stream) {
Table *t = new Table(size);
- fillBuffers(stream);
+ Script s(&stream, false);
+
+ s.readLineToken();
while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
t->addData(_tokens[0]);
- fillBuffers(stream);
+ s.readLineToken();
}
return t;
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp
index 70e43babba..c3f4e50cc1 100644
--- a/engines/parallaction/parser.cpp
+++ b/engines/parallaction/parser.cpp
@@ -30,7 +30,7 @@ namespace Parallaction {
char _tokens[20][40];
-Script::Script(Common::SeekableReadStream *input, bool disposeSource) : _input(input), _disposeSource(disposeSource) {
+Script::Script(Common::ReadStream *input, bool disposeSource) : _input(input), _disposeSource(disposeSource), _line(0) {
}
Script::~Script() {
@@ -50,6 +50,8 @@ char *Script::readLine(char *buf, size_t bufSize) {
if (!_input->eos() && _si < bufSize) buf[_si] = v2;
}
+ _line++;
+
if (_si == 0 && _input->eos())
return 0;
@@ -60,27 +62,9 @@ char *Script::readLine(char *buf, size_t bufSize) {
}
-uint32 Script::read(void *dataPtr, uint32 dataSize) {
- error("binary read not supported on Script streams");
-}
-bool Script::eos() const {
- error("EoS not supported on Script streams");
-}
-
-uint32 Script::pos() const {
- error("position not supported on Script streams");
-}
-
-uint32 Script::size() const {
- error("can't get size of Script streams");
-}
-
-void Script::seek(int32 offset, int whence) {
- error("seek not supported on Script streams");
-}
-void clearTokens() {
+void Script::clearTokens() {
for (uint16 i = 0; i < 20; i++)
_tokens[i][0] = '\0';
@@ -89,10 +73,10 @@ void clearTokens() {
}
-void skip(Script* script, const char* endToken) {
+void Script::skip(const char* endToken) {
while (scumm_stricmp(_tokens[0], endToken)) {
- fillBuffers(*script, true);
+ readLineToken(true);
}
}
@@ -165,7 +149,7 @@ char *parseNextToken(char *s, char *tok, uint16 count, const char *brk, bool ign
}
-uint16 fillTokens(char* line) {
+uint16 Script::fillTokens(char* line) {
uint16 i = 0;
while (strlen(line) > 0 && i < 20) {
@@ -177,14 +161,14 @@ uint16 fillTokens(char* line) {
return i;
}
-uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF) {
+uint16 Script::readLineToken(bool errorOnEOF) {
clearTokens();
char buf[200];
char *line = NULL;
do {
- line = stream.readLine(buf, 200);
+ line = readLine(buf, 200);
if (line == NULL) {
if (errorOnEOF)
error("unexpected end of file while parsing");
diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h
index 3d1b32ec3a..f566017c9a 100644
--- a/engines/parallaction/parser.h
+++ b/engines/parallaction/parser.h
@@ -32,32 +32,31 @@
namespace Parallaction {
-uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF = false);
char *parseNextToken(char *s, char *tok, uint16 count, const char *brk, bool ignoreQuotes = false);
extern char _tokens[][40];
-class Script : public Common::SeekableReadStream {
+class Script {
- Common::SeekableReadStream *_input;
+ Common::ReadStream *_input;
bool _disposeSource;
+ uint _line; // for debug messages
+
+ void clearTokens();
+ uint16 fillTokens(char* line);
public:
- Script(Common::SeekableReadStream *, bool _disposeSource = false);
+ Script(Common::ReadStream *, bool _disposeSource = false);
~Script();
- uint32 read(void *dataPtr, uint32 dataSize);
-
char *readLine(char *buf, size_t bufSize);
+ uint16 readLineToken(bool errorOnEOF = false);
- bool eos() const;
- uint32 pos() const;
- uint32 size() const;
+ void skip(const char* endToken);
- void seek(int32 offset, int whence = SEEK_SET);
+ uint getLine() { return _line; }
};
-void skip(Script* script, const char* endToken);
} // namespace Parallaction
diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp
index b92da0478f..d4fcceafd5 100644
--- a/engines/parallaction/parser_br.cpp
+++ b/engines/parallaction/parser_br.cpp
@@ -258,7 +258,7 @@ DECLARE_LOCATION_PARSER(character) {
DECLARE_LOCATION_PARSER(ifchar) {
debugC(7, kDebugParser, "LOCATION_PARSER(ifchar) ");
- skip(_locParseCtxt.script, "ENDIF");
+ _locParseCtxt.script->skip("ENDIF");
}
@@ -313,7 +313,7 @@ DECLARE_COMMAND_PARSER(ifchar) {
debugC(7, kDebugParser, "COMMAND_PARSER(ifchar) ");
if (!scumm_stricmp(_char.getName(), _tokens[1]))
- skip(_locParseCtxt.script, "endif");
+ _locParseCtxt.script->skip("endif");
}
diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp
index 885d147572..3e03c3458e 100644
--- a/engines/parallaction/parser_ns.cpp
+++ b/engines/parallaction/parser_ns.cpp
@@ -233,7 +233,7 @@ void Parallaction_ns::loadProgram(Animation *a, const char *filename) {
_instParseCtxt.program = a->_program;
do {
- fillBuffers(*script);
+ script->readLineToken();
parseInstruction(a, a->_program->_locals);
} while (!_instParseCtxt.end);
@@ -684,7 +684,7 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
Table forwards(20);
- fillBuffers(script, true);
+ script.readLineToken(true);
while (scumm_stricmp(_tokens[0], "enddialogue")) {
if (scumm_stricmp(_tokens[0], "Question")) continue;
@@ -696,12 +696,12 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
question->_text = parseDialogueString(script);
- fillBuffers(script, true);
+ script.readLineToken(true);
question->_mood = atoi(_tokens[0]);
uint16 numAnswers = 0;
- fillBuffers(script, true);
+ script.readLineToken(true);
while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers
Answer *answer = new Answer;
@@ -739,27 +739,27 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
answer->_text = parseDialogueString(script);
- fillBuffers(script, true);
+ script.readLineToken(true);
answer->_mood = atoi(_tokens[0]);
answer->_following._name = parseDialogueString(script);
- fillBuffers(script, true);
+ script.readLineToken(true);
if (!scumm_stricmp(_tokens[0], "commands")) {
parseCommands(script, answer->_commands);
_locParseCtxt.endcommands = false;
do {
- fillBuffers(script, true);
+ script.readLineToken(true);
parseStatement();
} while (!_locParseCtxt.endcommands);
- fillBuffers(script, true);
+ script.readLineToken(true);
}
numAnswers++;
}
- fillBuffers(script, true);
+ script.readLineToken(true);
numQuestions++;
}
@@ -971,7 +971,7 @@ void Parallaction_ns::parseLocation(const char *filename) {
pushParserTables(&_locationParsers, _locationStmt);
do {
- fillBuffers(*script, true);
+ script->readLineToken(true);
parseStatement();
} while (!_locParseCtxt.end);
popParserTables();
@@ -1000,7 +1000,7 @@ void Parallaction_ns::parseLocation(const char *filename) {
void Parallaction_ns::parseWalkNodes(Script& script, WalkNodeList &list) {
debugC(5, kDebugParser, "parseWalkNodes()");
- fillBuffers(script, true);
+ script.readLineToken(true);
while (scumm_stricmp(_tokens[0], "ENDNODES")) {
if (!scumm_stricmp(_tokens[0], "COORD")) {
@@ -1013,7 +1013,7 @@ void Parallaction_ns::parseWalkNodes(Script& script, WalkNodeList &list) {
list.push_front(v4);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
}
debugC(5, kDebugParser, "parseWalkNodes() done");
@@ -1246,7 +1246,7 @@ void Parallaction_ns::parseZone(Script &script, ZoneList &list, char *name) {
if (findZone(name)) {
while (scumm_stricmp(_tokens[0], "endzone")) {
- fillBuffers(script, true);
+ script.readLineToken(true);
}
return;
}
@@ -1288,7 +1288,7 @@ void Parallaction_ns::parseGetData(Script &script, Zone *z) {
data->_icon = 4 + _objectsNames->lookup(_tokens[1]);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.get = data;
@@ -1309,7 +1309,7 @@ void Parallaction_ns::parseExamineData(Script &script, Zone *z) {
data->_description = parseComment(script);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.examine = data;
@@ -1354,7 +1354,7 @@ void Parallaction_ns::parseDoorData(Script &script, Zone *z) {
data->_startFrame = atoi(_tokens[3]);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.door = data;
@@ -1378,7 +1378,7 @@ void Parallaction_ns::parseMergeData(Script &script, Zone *z) {
data->_obj3 = 4 + _objectsNames->lookup(_tokens[1]);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.merge = data;
@@ -1399,7 +1399,7 @@ void Parallaction_ns::parseHearData(Script &script, Zone *z) {
data->_freq = atoi(_tokens[1]);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.hear = data;
@@ -1419,7 +1419,7 @@ void Parallaction_ns::parseSpeakData(Script &script, Zone *z) {
data->_dialogue = parseDialogue(script);
}
- fillBuffers(script, true);
+ script.readLineToken(true);
} while (scumm_stricmp(_tokens[0], "endzone"));
z->u.speak = data;
@@ -1457,7 +1457,7 @@ void Parallaction_ns::parseZoneTypeBlock(Script &script, Zone *z) {
default:
// eats up 'ENDZONE' line for unprocessed zone types
- fillBuffers(script, true);
+ script.readLineToken(true);
break;
}