[Scummvm-cvs-logs] SF.net SVN: scummvm: [29221] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Oct 14 23:32:43 CEST 2007


Revision: 29221
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29221&view=rev
Author:   peres001
Date:     2007-10-14 14:32:43 -0700 (Sun, 14 Oct 2007)

Log Message:
-----------
Integrated low-level routines into the Script class, turning it into a self-contained parser for location, program and table scripts.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/objects.cpp
    scummvm/trunk/engines/parallaction/parser.cpp
    scummvm/trunk/engines/parallaction/parser.h
    scummvm/trunk/engines/parallaction/parser_br.cpp
    scummvm/trunk/engines/parallaction/parser_ns.cpp

Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp	2007-10-14 20:59:46 UTC (rev 29220)
+++ scummvm/trunk/engines/parallaction/objects.cpp	2007-10-14 21:32:43 UTC (rev 29221)
@@ -399,10 +399,12 @@
 
 	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;

Modified: scummvm/trunk/engines/parallaction/parser.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser.cpp	2007-10-14 20:59:46 UTC (rev 29220)
+++ scummvm/trunk/engines/parallaction/parser.cpp	2007-10-14 21:32:43 UTC (rev 29221)
@@ -30,7 +30,7 @@
 
 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 @@
 		if (!_input->eos() && _si < bufSize) buf[_si] = v2;
 	}
 
+	_line++;
+
 	if (_si == 0 && _input->eos())
 		return 0;
 
@@ -60,28 +62,10 @@
 
 }
 
-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");
-}
+void Script::clearTokens() {
 
-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() {
-
 	for (uint16 i = 0; i < 20; i++)
 		_tokens[i][0] = '\0';
 
@@ -89,10 +73,10 @@
 
 }
 
-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 @@
 
 }
 
-uint16 fillTokens(char* line) {
+uint16 Script::fillTokens(char* line) {
 
 	uint16 i = 0;
 	while (strlen(line) > 0 && i < 20) {
@@ -177,14 +161,14 @@
 	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");

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2007-10-14 20:59:46 UTC (rev 29220)
+++ scummvm/trunk/engines/parallaction/parser.h	2007-10-14 21:32:43 UTC (rev 29221)
@@ -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

Modified: scummvm/trunk/engines/parallaction/parser_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_br.cpp	2007-10-14 20:59:46 UTC (rev 29220)
+++ scummvm/trunk/engines/parallaction/parser_br.cpp	2007-10-14 21:32:43 UTC (rev 29221)
@@ -258,7 +258,7 @@
 DECLARE_LOCATION_PARSER(ifchar)  {
 	debugC(7, kDebugParser, "LOCATION_PARSER(ifchar) ");
 
-	skip(_locParseCtxt.script, "ENDIF");
+	_locParseCtxt.script->skip("ENDIF");
 }
 
 
@@ -313,7 +313,7 @@
 	debugC(7, kDebugParser, "COMMAND_PARSER(ifchar) ");
 
 	if (!scumm_stricmp(_char.getName(), _tokens[1]))
-		skip(_locParseCtxt.script, "endif");
+		_locParseCtxt.script->skip("endif");
 }
 
 

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2007-10-14 20:59:46 UTC (rev 29220)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2007-10-14 21:32:43 UTC (rev 29221)
@@ -233,7 +233,7 @@
 	_instParseCtxt.program = a->_program;
 
 	do {
-		fillBuffers(*script);
+		script->readLineToken();
 		parseInstruction(a, a->_program->_locals);
 	} while (!_instParseCtxt.end);
 
@@ -684,7 +684,7 @@
 
 	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 @@
 
 		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 @@
 
 			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 @@
 
 	pushParserTables(&_locationParsers, _locationStmt);
 	do {
-		fillBuffers(*script, true);
+		script->readLineToken(true);
 		parseStatement();
 	} while (!_locParseCtxt.end);
 	popParserTables();
@@ -1000,7 +1000,7 @@
 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 @@
 			list.push_front(v4);
 		}
 
-		fillBuffers(script, true);
+		script.readLineToken(true);
 	}
 
 	debugC(5, kDebugParser, "parseWalkNodes() done");
@@ -1246,7 +1246,7 @@
 
 	if (findZone(name)) {
 		while (scumm_stricmp(_tokens[0], "endzone")) {
-			fillBuffers(script, true);
+			script.readLineToken(true);
 		}
 		return;
 	}
@@ -1288,7 +1288,7 @@
 			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 @@
 			data->_description = parseComment(script);
 		}
 
-		fillBuffers(script, true);
+		script.readLineToken(true);
 	} while (scumm_stricmp(_tokens[0], "endzone"));
 
 	z->u.examine = data;
@@ -1354,7 +1354,7 @@
 			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 @@
 			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 @@
 			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 @@
 			data->_dialogue = parseDialogue(script);
 		}
 
-		fillBuffers(script, true);
+		script.readLineToken(true);
 	} while (scumm_stricmp(_tokens[0], "endzone"));
 
 	z->u.speak = data;
@@ -1457,7 +1457,7 @@
 
 	default:
 		// eats up 'ENDZONE' line for unprocessed zone types
-		fillBuffers(script, true);
+		script.readLineToken(true);
 		break;
 	}
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list