From 5f0f0193f921008bf2deb5e249e40936aada8483 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 15 Jul 2016 19:21:09 +0300 Subject: DIRECTOR: Lingo: Fix splitting code to sections --- engines/director/lingo/lingo.cpp | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 837dfa0b67..8302c5996e 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -106,25 +106,35 @@ Lingo::~Lingo() { } const char *Lingo::findNextDefinition(const char *s) { - const char *res; + const char *res = s; - 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) + while (*res) { + while (*res && (*res == ' ' || *res == '\t' || *res == '\n')) + res++; + + if (!*res) + return NULL; + + if (!strncmp(res, "macro ", 6)) { + warning("See macro"); + return res; + } + + if (!strncmp(res, "factory ", 8)) { + warning("See factory"); 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') + if (!strncmp(res, "method ", 7)) { + warning("See method"); return res; + } + + while (*res && *res != '\n') + res++; } - return nullptr; + return NULL; } void Lingo::addCode(const char *code, ScriptType type, uint16 id) { @@ -147,14 +157,13 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { if ((begin = findNextDefinition(code))) { bool first = true; - begin += 1; + while ((end = findNextDefinition(begin + 1))) { - while ((end = findNextDefinition(begin))) { if (first) { begin = code; first = false; } - Common::String chunk(begin, end + 1); + Common::String chunk(begin, end - 1); if (chunk.hasPrefix("factory") || chunk.hasPrefix("method")) _inFactory = true; @@ -163,13 +172,13 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) { else _inFactory = false; - debug(2, "Code chunk\n#####\n%s#####", chunk.c_str()); + debug(2, "Code chunk:\n#####\n%s#####", chunk.c_str()); parse(chunk.c_str()); _currentScript->clear(); - begin = end + 1; + begin = end; } _hadError = true; // HACK: This is for preventing test execution -- cgit v1.2.3