diff options
author | Paul Gilbert | 2019-11-08 22:30:52 -0800 |
---|---|---|
committer | Paul Gilbert | 2019-11-11 18:20:30 -0800 |
commit | 5d8b8752e82abb91746c01dd61865d0ad6944e3d (patch) | |
tree | f5292611efd88a6a0a63ddfad9b5a5a8c5553b7d /engines/glk/archetype | |
parent | 38e5463601d7d8cb0687076adba488f8ea398d92 (diff) | |
download | scummvm-rg350-5d8b8752e82abb91746c01dd61865d0ad6944e3d.tar.gz scummvm-rg350-5d8b8752e82abb91746c01dd61865d0ad6944e3d.tar.bz2 scummvm-rg350-5d8b8752e82abb91746c01dd61865d0ad6944e3d.zip |
GLK: ARCHETYPE: Script handler fixes
Diffstat (limited to 'engines/glk/archetype')
-rw-r--r-- | engines/glk/archetype/archetype.cpp | 25 | ||||
-rw-r--r-- | engines/glk/archetype/interpreter.cpp | 5 | ||||
-rw-r--r-- | engines/glk/archetype/string.cpp | 22 |
3 files changed, 40 insertions, 12 deletions
diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp index 8aeafa1172..38eb83fc83 100644 --- a/engines/glk/archetype/archetype.cpp +++ b/engines/glk/archetype/archetype.cpp @@ -433,6 +433,7 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co break; default: + result = *the_expr; break; } } else if (the_expr->_kind == OPER) { @@ -645,7 +646,8 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co if (the_expr->_data._oper.op_name == OP_LEFTFROM) result._data._str.acl_str = MakeNewDynStr(r1._data._str.acl_str->left(r2._data._numeric.acl_int)); else - result._data._str.acl_str = MakeNewDynStr(r1._data._str.acl_str->right(r2._data._numeric.acl_int)); + result._data._str.acl_str = MakeNewDynStr(r1._data._str.acl_str->right( + r1._data._str.acl_str->size() - r2._data._numeric.acl_int + 1)); } break; @@ -654,7 +656,7 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co eval_expr(the_expr->_data._oper.right, r2, context, RVALUE); if (convert_to(STR_PTR, r1) && convert_to(STR_PTR, r2)) { result._kind = NUMERIC; - result._data._numeric.acl_int = r2._data._str.acl_str->indexOf(*r1._data._str.acl_str); + result._data._numeric.acl_int = r2._data._str.acl_str->indexOf(*r1._data._str.acl_str) + 1; if (result._data._numeric.acl_int == 0) cleanup(result); } @@ -712,8 +714,11 @@ bool Archetype::eval_condition(ExprTree the_expr, ContextType &context) { undefine(result); eval_expr(the_expr, result, context, RVALUE); - failure = (result._kind == RESERVED) && (result._data._reserved.keyword = RW_UNDEFINED - || result._data._reserved.keyword == RW_FALSE || result._data._reserved.keyword == RW_ABSENT); + failure = (result._kind == RESERVED) && ( + result._data._reserved.keyword == RW_UNDEFINED || + result._data._reserved.keyword == RW_FALSE || + result._data._reserved.keyword == RW_ABSENT + ); cleanup(result); return !failure; @@ -767,6 +772,8 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType case MESSAGE: b = send_message(OP_PASS, the_stmt->_data._expr.expression->_data._msgTextQuote.index, context.self, result, context); + break; + default: eval_expr(the_stmt->_data._expr.expression, result, context, RVALUE); break; @@ -811,8 +818,7 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType if (the_stmt->_kind == ST_WRITE) { wrapout("", true); - } - else if (the_stmt->_kind == ST_STOP) { + } else if (the_stmt->_kind == ST_STOP) { g_vm->writeln(); g_vm->writeln(); error("%f", VERSION_NUM); @@ -826,13 +832,12 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType } if (eval_condition(the_stmt->_data._if.condition, context)) { if (verbose) - debug(" Evaluated true; executing then branch"); + debug(" Evaluated TRUE; executing then branch"); exec_stmt(the_stmt->_data._if.then_branch, result, context); - } - else if (the_stmt->_data._if.else_branch != nullptr) { + } else if (the_stmt->_data._if.else_branch != nullptr) { if (verbose) - debug(" Evaluated false; executing else branch"); + debug(" Evaluated FALSE; executing else branch"); exec_stmt(the_stmt->_data._if.else_branch, result, context); } break; diff --git a/engines/glk/archetype/interpreter.cpp b/engines/glk/archetype/interpreter.cpp index 0ace84e58a..a9ee1bbb51 100644 --- a/engines/glk/archetype/interpreter.cpp +++ b/engines/glk/archetype/interpreter.cpp @@ -295,6 +295,7 @@ bool result_compare(short comparison, ResultType &r1, ResultType &r2) { default: break; } + break; case IDENT: if (r1._data._ident.ident_kind == r2._data._ident.ident_kind) { @@ -380,8 +381,10 @@ void display_result(ResultType &result) { break; case MESSAGE: enclose = "\'"; + break; default: enclose = ' '; + break; } if (enclose != " ") @@ -401,7 +404,7 @@ void display_expr(ExprTree the_tree) { debugN(") "); } - wrapout(Operators[the_tree->_data._oper.op_name], false); + debugN(Operators[the_tree->_data._oper.op_name]); debugN(" ("); display_expr(the_tree->_data._oper.right); debugN(") "); diff --git a/engines/glk/archetype/string.cpp b/engines/glk/archetype/string.cpp index 4db4688a7d..9295ced210 100644 --- a/engines/glk/archetype/string.cpp +++ b/engines/glk/archetype/string.cpp @@ -98,10 +98,30 @@ String String::vformat(const char *fmt, va_list args) { } int String::val(int *code) { + const char *srcP = c_str(); + int result = 0, sign = 0, idx = 1; + + if (*srcP == '-') { + sign = -1; + ++srcP; + ++idx; + } + + for (; *srcP; ++srcP, ++idx) { + if (*srcP < '0' || *srcP > '9') { + // Invalid character + if (code) + *code = idx; + return result; + } + + result = (result * 10) + (*srcP - '0'); + } + if (code) *code = 0; - return atoi(c_str()); + return result; } String String::left(size_t count) const { |