From 65a1856ab0de76c3759aad8ae83506322a76c2fb Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 7 Dec 2019 10:21:26 +0100 Subject: DIRECTOR: LINGO: Added debug output to preprocessor --- engines/director/lingo/lingo.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'engines') diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 8dde6dbfe7..ac725e5079 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -318,29 +318,37 @@ Common::String Lingo::stripComments(const char *s) { line += tolower(*s++); } } + debugC(2, kDebugLingoParse, "line: %d '%s'", iflevel, line.c_str()); if (line.size() < 4) { // If line is too small, then skip it if (*s) // copy newline symbol res += *s++; + debugC(2, kDebugLingoParse, "too small"); + continue; } tok = nexttok(line.c_str(), &lineStart); if (tok.equals("if")) { tok = prevtok(&line.c_str()[line.size() - 1], lineStart, &prevEnd); + debugC(2, kDebugLingoParse, "start-if <%s>", tok.c_str()); if (tok.equals("if")) { + debugC(2, kDebugLingoParse, "end-if"); tok = prevtok(prevEnd, lineStart); if (tok.equals("end")) { // do nothing, we open and close same line + debugC(2, kDebugLingoParse, "end-end"); } else { iflevel++; } } else if (tok.equals("then")) { + debugC(2, kDebugLingoParse, "last-then"); iflevel++; } else if (tok.equals("else")) { + debugC(2, kDebugLingoParse, "last-else"); iflevel++; } else { // other token // Now check if we have tNLELSE @@ -355,35 +363,46 @@ Common::String Lingo::stripComments(const char *s) { tok = nexttok(s1); if (tok.equalsIgnoreCase("else")) { // ignore case because it is look-ahead + debugC(2, kDebugLingoParse, "tNLELSE"); iflevel++; } else { + debugC(2, kDebugLingoParse, "++++ end if (no nlelse after single liner)"); res += " end if"; iflevel--; } } } else if (tok.equals("else")) { + debugC(2, kDebugLingoParse, "start-else"); bool elseif = false; tok = nexttok(lineStart); if (tok.equals("if")) { + debugC(2, kDebugLingoParse, "second-if"); elseif = true; } else if (tok.empty()) { + debugC(2, kDebugLingoParse, "lonely-else"); continue; } tok = prevtok(&line.c_str()[line.size() - 1], lineStart, &prevEnd); + debugC(2, kDebugLingoParse, "last: '%s'", tok.c_str()); if (tok.equals("if")) { + debugC(2, kDebugLingoParse, "end-if"); tok = prevtok(prevEnd, lineStart); if (tok.equals("end")) { + debugC(2, kDebugLingoParse, "end-end"); iflevel--; } } else if (tok.equals("then")) { + debugC(2, kDebugLingoParse, "last-then"); + if (elseif == false) { warning("Badly nested then"); } } else if (tok.equals("else")) { + debugC(2, kDebugLingoParse, "last-else"); if (elseif == false) { warning("Badly nested else"); } @@ -399,23 +418,32 @@ Common::String Lingo::stripComments(const char *s) { if (tok.equalsIgnoreCase("else")) { // Nothing to do here, same level + debugC(2, kDebugLingoParse, "tNLELSE"); } else { + debugC(2, kDebugLingoParse, "++++ end if (no tNLELSE)"); res += " end if"; iflevel--; } } } else if (tok.equals("end")) { + debugC(2, kDebugLingoParse, "start-end"); + tok = nexttok(lineStart); if (tok.equals("if")) { + debugC(2, kDebugLingoParse, "second-if"); iflevel--; } } } for (int i = 0; i < iflevel; i++) { + debugC(2, kDebugLingoParse, "++++ end if (unclosed)"); res += "\nend if"; } + + debugC(2, kDebugLingoParse, "#############\n%s\n#############", res.c_str()); + return res; } -- cgit v1.2.3