diff options
author | Eugene Sandulenko | 2016-07-13 07:42:44 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-08-03 23:40:36 +0200 |
commit | a84d8c44e4053aa4210bb18e7235199a3d91e45d (patch) | |
tree | a30700415d4d64e4de3bfae1bdee295ea23b8772 /engines/director/lingo/lingo.cpp | |
parent | 8b20d3d67bcec592999376ca0cb3d3dede4d6789 (diff) | |
download | scummvm-rg350-a84d8c44e4053aa4210bb18e7235199a3d91e45d.tar.gz scummvm-rg350-a84d8c44e4053aa4210bb18e7235199a3d91e45d.tar.bz2 scummvm-rg350-a84d8c44e4053aa4210bb18e7235199a3d91e45d.zip |
DIRECTOR: Lingo: Initial code for splitting factory and method input
Diffstat (limited to 'engines/director/lingo/lingo.cpp')
-rw-r--r-- | engines/director/lingo/lingo.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index ccbb66898d..837dfa0b67 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -94,6 +94,8 @@ Lingo::Lingo(DirectorEngine *vm) : _vm(vm) { _hadError = false; + _inFactory = false; + _floatPrecision = 4; _floatPrecisionFormat = "%.4f"; @@ -103,6 +105,28 @@ Lingo::Lingo(DirectorEngine *vm) : _vm(vm) { Lingo::~Lingo() { } +const char *Lingo::findNextDefinition(const char *s) { + const char *res; + + if ((res = strstr(s, "\nmacro "))) { + return res; + } else if ((res = strstr(s, "\nfactory "))) { + return res; + } else if (_inFactory && (res = strstr(s, "method "))) { + if (s == res) + return res; + + // Check that this is the first token on the line + const char *tres = res; + while (tres > s && (*tres == ' ' || *tres == '\t') && *tres != '\n') + tres--; + if (*tres == '\n') + return res; + } + + return nullptr; +} + void Lingo::addCode(const char *code, ScriptType type, uint16 id) { debug(2, "Add code \"%s\" for type %d with id %d", code, type, id); @@ -119,19 +143,26 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { const char *begin, *end; - // macros have conflicting grammar. Thus we ease life for the parser. - if ((begin = strstr(code, "\nmacro "))) { + // macros and factories have conflicting grammar. Thus we ease life for the parser. + if ((begin = findNextDefinition(code))) { bool first = true; begin += 1; - while ((end = strstr(begin, "\nmacro "))) { + while ((end = findNextDefinition(begin))) { if (first) { begin = code; first = false; } Common::String chunk(begin, end + 1); + if (chunk.hasPrefix("factory") || chunk.hasPrefix("method")) + _inFactory = true; + else if (chunk.hasPrefix("macro")) + _inFactory = false; + else + _inFactory = false; + debug(2, "Code chunk\n#####\n%s#####", chunk.c_str()); parse(chunk.c_str()); @@ -149,6 +180,8 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { code1(STOP); } + _inFactory = false; + if (_currentScript->size() && !_hadError) Common::hexdump((byte *)&_currentScript->front(), _currentScript->size() * sizeof(inst)); } |