From ab5939ba443b31cbecb727825346a331a84856a7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Nov 2019 19:42:06 -0800 Subject: GLK: ARCHETYPE: Fix quitting the game --- engines/glk/archetype/archetype.cpp | 10 ++++++---- engines/glk/archetype/interpreter.cpp | 15 +++++++++++---- engines/glk/archetype/interpreter.h | 5 +++++ 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'engines/glk/archetype') diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp index 3792938b8b..395edd6753 100644 --- a/engines/glk/archetype/archetype.cpp +++ b/engines/glk/archetype/archetype.cpp @@ -125,7 +125,7 @@ void Archetype::interpret() { void Archetype::write(const String fmt, ...) { va_list ap; va_start(ap, fmt); - Common::String s = Common::String::format(fmt.c_str(), ap); + Common::String s = Common::String::vformat(fmt.c_str(), ap); va_end(ap); glk_put_buffer(s.c_str(), s.size()); @@ -134,7 +134,7 @@ void Archetype::write(const String fmt, ...) { void Archetype::writeln(const String fmt, ...) { va_list ap; va_start(ap, fmt); - Common::String s = Common::String::format(fmt.c_str(), ap); + Common::String s = Common::String::vformat(fmt.c_str(), ap); va_end(ap); s += '\n'; @@ -826,7 +826,8 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType while (iterate_list(the_stmt->_data._write.print_list, np)) { cleanup(result); eval_expr((ExprTree)np->data, result, context, RVALUE); - write_result(result); + String line = get_result_string(result); + g_vm->write("%s", line.c_str()); } if (the_stmt->_kind == ST_WRITE) { @@ -834,7 +835,8 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType } else if (the_stmt->_kind == ST_STOP) { g_vm->writeln(); g_vm->writeln(); - error("%f", VERSION_NUM); + g_vm->writeln("%f", VERSION_NUM); + g_vm->quitGame(); } break; diff --git a/engines/glk/archetype/interpreter.cpp b/engines/glk/archetype/interpreter.cpp index 15328a1dab..654a3019bb 100644 --- a/engines/glk/archetype/interpreter.cpp +++ b/engines/glk/archetype/interpreter.cpp @@ -347,23 +347,30 @@ bool assignment(ResultType &target, ResultType &value) { return true; } -void write_result(ResultType &result) { +String get_result_string(ResultType &result) { ResultType r1; + String str; undefine(r1); if (result._kind == STR_PTR) - debugN(result._data._str.acl_str->c_str()); + str = result._data._str.acl_str->c_str(); else if (result._kind == RESERVED) - debugN(Reserved_Wds[result._data._reserved.keyword]); + str = Reserved_Wds[result._data._reserved.keyword]; else { if (result._kind == ATTR_PTR) copy_result(r1, *(ResultType *)result._data._attr.acl_attr->data); else copy_result(r1, result); if (convert_to(STR_PTR, r1)) - debugN(r1._data._str.acl_str->c_str()); + str = r1._data._str.acl_str->c_str(); cleanup(r1); } + + return str; +} + +void write_result(ResultType &result) { + debugN("%s", get_result_string(result).c_str()); } void display_result(ResultType &result) { diff --git a/engines/glk/archetype/interpreter.h b/engines/glk/archetype/interpreter.h index 331cd7a6f7..2b5c8d84dd 100644 --- a/engines/glk/archetype/interpreter.h +++ b/engines/glk/archetype/interpreter.h @@ -101,6 +101,11 @@ extern bool result_compare(short comparison, ResultType &r1, ResultType &r2); */ extern bool assignment(ResultType &target, ResultType &value); +/** + * Gets a textual version of a passed result + */ +extern String get_result_string(ResultType &result); + /** * Writes the given result to screen w/o terminating it with a newline */ -- cgit v1.2.3