diff options
| -rw-r--r-- | engines/parallaction/parser.cpp | 180 | ||||
| -rw-r--r-- | engines/parallaction/parser.h | 113 | ||||
| -rw-r--r-- | engines/parallaction/parser_br.cpp | 24 | 
3 files changed, 1 insertions, 316 deletions
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp index 2ad65abf20..bfd16de73d 100644 --- a/engines/parallaction/parser.cpp +++ b/engines/parallaction/parser.cpp @@ -254,184 +254,4 @@ void Parser::parseStatement() {  } -#define BLOCK_BASE	100 - -class StatementDef { -protected: -	Common::String makeLineFromTokens() { -		Common::String space(" "); -		Common::String newLine("\n"); -		Common::String text; -		for (int i = 0; i < _numTokens; i++) -			text += (Common::String(_tokens[i]) + space); -		text.deleteLastChar(); -		text += newLine; -		return text; -	} - -public: -	uint _score; -	const char*	_name; - - -	StatementDef(uint score, const char *name) : _score(score), _name(name) { } -	virtual ~StatementDef() { } - -	virtual Common::String makeLine(Script &script) = 0; - -}; - - -class SimpleStatementDef : public StatementDef { - -public: -	SimpleStatementDef(uint score, const char *name) : StatementDef(score, name) { } - -	Common::String makeLine(Script &script) { -		return makeLineFromTokens(); -	} - -}; - - - -class BlockStatementDef : public StatementDef { - -	const char*	_ending1; -	const char*	_ending2; - -public: -	BlockStatementDef(uint score, const char *name, const char *ending1, const char *ending2 = 0) : StatementDef(score, name), _ending1(ending1), -		_ending2(ending2) { } - -	Common::String makeLine(Script &script) { -		Common::String text = makeLineFromTokens(); -		bool end; -		do { -			script.readLineToken(true); -			text += makeLineFromTokens(); -			end = !scumm_stricmp(_ending1, _tokens[0]) || (_ending2 && !scumm_stricmp(_ending2, _tokens[0])); -		} while (!end); -		return text; -	} - -}; - -class CommentStatementDef : public StatementDef { - -	Common::String parseComment(Script &script) { -		Common::String result; -		char buf[401]; -		do { -			char *line = script.readLine(buf, 400); -			if (!scumm_stricmp(line, "endtext")) -				break; -			result += Common::String(line) + "\n"; -		} while (true); -		result += "endtext\n"; -		return result; -	} - -public: -	CommentStatementDef(uint score, const char *name) : StatementDef(score, name) { } - -	Common::String makeLine(Script &script) { -		Common::String text = makeLineFromTokens(); -		text += parseComment(script); -		return text; -	} - -}; - - - - -PreProcessor::PreProcessor() { -	_defs.push_back(new SimpleStatementDef(1, "disk" )); -	_defs.push_back(new SimpleStatementDef(2, "location" )); -	_defs.push_back(new SimpleStatementDef(3, "localflags" )); -	_defs.push_back(new SimpleStatementDef(4, "flags" )); -	_defs.push_back(new SimpleStatementDef(5, "zeta" )); -	_defs.push_back(new SimpleStatementDef(6, "music" )); -	_defs.push_back(new SimpleStatementDef(7, "sound" )); -	_defs.push_back(new SimpleStatementDef(8, "mask" )); -	_defs.push_back(new SimpleStatementDef(9, "path" )); -	_defs.push_back(new SimpleStatementDef(10, "character" )); -	_defs.push_back(new CommentStatementDef(11, "comment" )); -	_defs.push_back(new CommentStatementDef(12, "endcomment" )); -	_defs.push_back(new BlockStatementDef(13,  "ifchar", "endif" )); -	_defs.push_back(new BlockStatementDef(BLOCK_BASE, "zone", "endanimation", "endzone" )); -	_defs.push_back(new BlockStatementDef(BLOCK_BASE, "animation", "endanimation", "endzone" )); -	_defs.push_back(new BlockStatementDef(1000, "commands", "endcommands" )); -	_defs.push_back(new BlockStatementDef(1001, "acommands", "endcommands" )); -	_defs.push_back(new BlockStatementDef(1002, "escape", "endcommands" )); -	_defs.push_back(new SimpleStatementDef(2000, "endlocation")); -} - -PreProcessor::~PreProcessor() { -	DefList::iterator it = _defs.begin(); -	for (; it != _defs.end(); it++) { -		delete *it; -	} -} - -StatementDef* PreProcessor::findDef(const char* name) { -	DefList::iterator it = _defs.begin(); -	for (; it != _defs.end(); it++) { -		if (!scumm_stricmp((*it)->_name, name)) { -			return *it; -		} -	} -	return 0; -} - - - -uint PreProcessor::getDefScore(StatementDef* def) { -	if (def->_score == BLOCK_BASE) { -		_numZones++; -		return (_numZones + BLOCK_BASE); -	} -	return def->_score; -} - - -void PreProcessor::preprocessScript(Script &script, StatementList &list) { -	_numZones = 0; -	Common::String text; -	do { -		if (script.readLineToken(false) == 0) -			break; - -		StatementDef *def = findDef(_tokens[0]); -		if (!def) { -			error("PreProcessor::preprocessScript: unknown statement '%s' found\n", _tokens[0]); -		} - -		text = def->makeLine(script); -		int score = getDefScore(def); -		list.push_back(StatementListNode(score, def->_name, text)); -	} while (true); -	Common::sort(list.begin(), list.end()); -} - - - - -void testPreprocessing(Parallaction *vm, const char *filename) { -	Script *script = vm->_disk->loadLocation(filename); -	StatementList list; -	PreProcessor pp; -	pp.preprocessScript(*script, list); -	delete script; -	Common::DumpFile dump; -	dump.open(filename); -	StatementList::iterator it = list.begin(); -	for ( ; it != list.end(); it++) { -		dump.write((*it)._text.c_str(), (*it)._text.size()); -	} -	dump.close(); -} - -  } // namespace Parallaction diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index 48facb620e..f83fc1384b 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -415,119 +415,6 @@ public:  }; -/* -	This simple stream is temporarily needed to hook the -	preprocessor output to the parser. It will go away -	when the parser is rewritten to fully exploit the -	statement list provided by the preprocessor. -*/ - -class ReadStringStream : public Common::ReadStream { - -	char *_text; -	uint32	_pos; -	uint32	_size; -	bool _eos; - -public: -	ReadStringStream(const Common::String &text) { -		_text = new char[text.size() + 1]; -		strcpy(_text, text.c_str()); -		_size = text.size(); -		_pos = 0; -		_eos = false; -	} - -	~ReadStringStream() { -		delete []_text; -	} - -	uint32 read(void *buffer, uint32 size) { -		if (_pos + size > _size) { -			size = _size - _pos; -			_eos = true; -		} -		memcpy(buffer, _text + _pos, size); -		_pos += size; -		return size; -	} - -	bool eos() const { -		return _eos; -	} - -}; - - -/* -	Demented as it may sound, the success of a parsing operation in the -	original BRA depends on what has been parsed before. The game features -	an innovative chaos system that involves the parser and the very game -	engine, in order to inflict the user an unforgettable game experience. - -	Ok, now for the serious stuff. - -	The PreProcessor implemented here fixes the location scripts before -	they are fed to the parser. It tries to do so by a preliminary scan -	of the text file, during which a score is assigned to each statement -	(more on this later). When the whole file has been analyzed, the -	statements are sorted according to their score, to create a parsable -	sequence. - -	For parsing, the statements in location scripts can be conveniently -	divided into 3 groups: - -	* location definitions -	* element definitions -	* start-up commands - -	Since the parsing of element definitions requires location parameters -	to be set, location definitions should be encountered first in the -	script. Start-up commands in turn may reference elements, so they can -	be parsed last. The first goal is to make sure the parser gets these -	three sets in this order. - -	Location definitions must also be presented in a certain sequence, -	because resource files are not fully self-describing. In short, some -	critical game data in contained in certain files, that must obviously -	be read before any other can be analyzed. This is the second goal. - -	TODO: some words about actual implementation. -*/ - -class StatementDef; - -struct StatementListNode { -	int	_score; -	Common::String	_name; -	Common::String	_text; - -	StatementListNode(int score, const Common::String &name, const Common::String &text) : _score(score), _name(name), _text(text) { } - -	bool operator<(const StatementListNode& node) const { -		return _score < node._score; -	} -}; -typedef Common::List<StatementListNode> StatementList; - - -class PreProcessor { -	typedef Common::List<StatementDef*> DefList; - -	int _numZones; -	DefList _defs; - -	StatementDef* findDef(const char* name); -	uint getDefScore(StatementDef*); - -public: -	PreProcessor(); -	~PreProcessor(); -	void preprocessScript(Script &script, StatementList &list); -}; - - -  } // namespace Parallaction  #endif diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index 526cc1397d..8abf8fc4c4 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -1210,32 +1210,12 @@ void ProgramParser_br::init() {  	INSTRUCTION_PARSER(endscript);  } - -/* -	Ancillary routine to support hooking preprocessor and -	parser. -*/ -Common::ReadStream *getStream(StatementList &list) { -	Common::String text; -	StatementList::iterator it = list.begin(); -	for ( ; it != list.end(); it++) { -		text += (*it)._text; -	} -	return new ReadStringStream(text); -} -  void LocationParser_br::parse(Script *script) { - -	PreProcessor pp; -	StatementList list; -	pp.preprocessScript(*script, list); -	Script *script2 = new Script(getStream(list), true); -  	ctxt.numZones = 0;  	ctxt.characterName = 0;  	ctxt.info = new BackgroundInfo; -	LocationParser_ns::parse(script2); +	LocationParser_ns::parse(script);  	_vm->_gfx->setBackground(kBackgroundLocation, ctxt.info); @@ -1250,8 +1230,6 @@ void LocationParser_br::parse(Script *script) {  	}  	free(ctxt.characterName); - -	delete script2;  }  } // namespace Parallaction  | 
