diff options
Diffstat (limited to 'engines/parallaction/parser.cpp')
-rw-r--r-- | engines/parallaction/parser.cpp | 180 |
1 files changed, 0 insertions, 180 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 |