aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/scriptconsole.cpp49
-rw-r--r--engines/sci/engine/scriptdebug.cpp25
-rw-r--r--engines/sci/engine/vm.cpp4
3 files changed, 44 insertions, 34 deletions
diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp
index 054d1e4e97..80993ae4db 100644
--- a/engines/sci/engine/scriptconsole.cpp
+++ b/engines/sci/engine/scriptconsole.cpp
@@ -30,6 +30,10 @@
#include "sci/engine/state.h"
#include "sci/scicore/sciconsole.h"
+
+#include "sci/sci.h" // For _console only
+#include "sci/console.h" // For _console only
+
namespace Sci {
#ifdef SCI_CONSOLE
@@ -121,7 +125,7 @@ void _cmd_exit() {
free(cmd_mm[t].data);
}
-static cmd_mm_entry_t *cmd_mm_find(char *name, int type) {
+static cmd_mm_entry_t *cmd_mm_find(const char *name, int type) {
int i;
for (i = 0; i < cmd_mm[type].entries; i++) {
@@ -397,10 +401,6 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on
}
void con_parse(EngineState *s, const char *command) {
- int quote = 0; // quoting?
- int done = 0; // are we done yet?
- int cdone = 0; // Done with the current command?
- const char *paramt; // parameter types
char *cmd = (command && command[0]) ? (char *)sci_strdup(command) : (char *)sci_strdup(" ");
char *_cmd = cmd;
int pos = 0;
@@ -408,9 +408,12 @@ void con_parse(EngineState *s, const char *command) {
if (!_cmd_initialized)
con_init();
+ bool done = false; // are we done yet?
while (!done) {
cmd_command_t *command_todo;
- int onvar = 1; // currently working on a variable?
+ bool quote = false; // quoting?
+ bool cdone = false; // Done with the current command?
+ bool onvar = true; // currently working on a variable?
cdone = 0;
pos = 0;
@@ -422,25 +425,27 @@ void con_parse(EngineState *s, const char *command) {
while (!cdone) {
switch (cmd[pos]) {
case 0:
- done = 1;
+ cdone = done = true;
case ';':
if (!quote)
- cdone = 1;
+ cdone = true;
case ' ':
- if (!quote)
- cmd[pos] = onvar = 0;
+ if (!quote) {
+ cmd[pos] = 0;
+ onvar = false;
+ }
break;
case '\\': // don't check next char for special meaning
memmove(cmd + pos, cmd + pos + 1, strlen(cmd + pos) - 1);
break;
case '"':
- quote ^= 1;
+ quote = !quote;
memmove(cmd + pos, cmd + pos + 1, strlen(cmd + pos));
pos--;
break;
default:
if (!onvar) {
- onvar = 1;
+ onvar = true;
cmd_param_t tmp;
tmp.str = cmd + pos;
cmdParams.push_back(tmp);
@@ -460,7 +465,7 @@ void con_parse(EngineState *s, const char *command) {
uint minparams;
int need_state = 0;
- paramt = command_todo->param;
+ const char *paramt = command_todo->param; // parameter types
if (command_todo->param[0] == '!') {
need_state = 1;
paramt++;
@@ -641,6 +646,8 @@ int con_hook_command(ConCommand command, const char *name, const char *param, co
cmd->param = param;
cmd->description = description;
+ ((SciEngine *)g_engine)->_console->con_hook_command(command, name, param, description);
+
return 0;
}
@@ -664,7 +671,7 @@ int con_hook_int(int *pointer, const char *name, const char *description) {
// Console commands and support functions
-static ResourceType parseResourceType(char *resid) {
+static ResourceType parseResourceType(const char *resid) {
// Gets the resource number of a resource string, or returns -1
ResourceType res = kResourceTypeInvalid;
@@ -830,14 +837,14 @@ static int c_list(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
static int c_man(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
int section = 0;
- unsigned int i;
- char *name = cmdParams[0].str;
- char *c = strchr(name, '.');
+ uint i;
+ Common::String name = cmdParams[0].str;
+ const char *c = strchr(name.c_str(), '.');
cmd_mm_entry_t *entry = 0;
if (c) {
- *c = 0;
section = atoi(c + 1);
+ name = Common::String(name.begin(), c);
}
if (section < 0 || section >= CMD_MM_ENTRIES) {
@@ -847,10 +854,10 @@ static int c_man(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
sciprintf("section:%d\n", section);
if (section)
- entry = cmd_mm_find(name, section - 1);
+ entry = cmd_mm_find(name.c_str(), section - 1);
else
for (i = 0; i < CMD_MM_ENTRIES && !section; i++) {
- if ((entry = cmd_mm_find(name, i)))
+ if ((entry = cmd_mm_find(name.c_str(), i)))
section = i + 1;
}
@@ -859,7 +866,7 @@ static int c_man(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
return 1;
}
- sciprintf("-- %s: %s.%d\n", cmd_mm[section - 1].name, name, section);
+ sciprintf("-- %s: %s.%d\n", cmd_mm[section - 1].name, name.c_str(), section);
cmd_mm[section - 1].print(entry, 1);
return 0;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 0bfb46df1f..3463ff794c 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -777,9 +777,9 @@ int c_sim_parse(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
for (i = 0; i < cmdParams.size(); i++) {
int flag = 0;
- char *token = cmdParams[i].str;
+ Common::String token = cmdParams[i].str;
- if (strlen(token) == 1) {// could be an operator
+ if (token.size() == 1) {// could be an operator
int j = 0;
while (operators[j] && (operators[j] != token[0]))
j++;
@@ -791,24 +791,24 @@ int c_sim_parse(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
}
if (!flag) {
- char *openb = strchr(token, '['); // look for opening braces
+ const char *openb = strchr(token.c_str(), '['); // look for opening braces
ResultWord result;
if (openb)
- *openb = 0; // remove them and the rest
+ token = Common::String(token.begin(), openb); // remove them and the rest
- result = vocab_lookup_word(token, strlen(token), s->_parserWords, s->_parserSuffixes);
+ result = vocab_lookup_word(token.c_str(), token.size(), s->_parserWords, s->_parserSuffixes);
if (result._class != -1) {
s->parser_nodes[i].type = 0;
s->parser_nodes[i].content.value = result._group;
} else { // group name was specified directly?
- int val = strtol(token, NULL, 0);
+ int val = strtol(token.c_str(), NULL, 0);
if (val) {
s->parser_nodes[i].type = 0;
s->parser_nodes[i].content.value = val;
} else { // invalid and not matched
- sciprintf("Couldn't interpret '%s'\n", token);
+ sciprintf("Couldn't interpret '%s'\n", token.c_str());
s->parser_valid = 0;
return 1;
}
@@ -935,7 +935,7 @@ enum {
};
int _parse_getinp(int *i, int *nr, const Common::Array<cmd_param_t> &cmdParams) {
- char *token;
+ const char *token;
if ((unsigned)*i == cmdParams.size())
return _parse_eoi;
@@ -1014,7 +1014,7 @@ int c_set_parse_nodes(EngineState *s, const Common::Array<cmd_param_t> &cmdParam
int c_parse(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
ResultWordList words;
char *error;
- char *string;
+ const char *string;
if (!s) {
sciprintf("Not in debug state\n");
@@ -2144,7 +2144,7 @@ static int c_set_acc(EngineState *s, const Common::Array<cmd_param_t> &cmdParams
static int c_send(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
reg_t object = cmdParams[0].reg;
- char *selector_name = cmdParams[1].str;
+ const char *selector_name = cmdParams[1].str;
StackPtr stackframe = s->_executionStack[0].sp;
int selector_id;
unsigned int i;
@@ -2230,7 +2230,7 @@ struct generic_config_flag_t {
};
static void handle_config_update(const generic_config_flag_t *flags_list, int flags_nr, const char *subsystem,
- int *active_options_p, char *changestring /* or NULL to display*/) {
+ int *active_options_p, const char *changestring /* or NULL to display*/) {
if (!changestring) {
int j;
@@ -2283,7 +2283,6 @@ static void handle_config_update(const generic_config_flag_t *flags_list, int fl
static int c_handle_config_update(const generic_config_flag_t *flags, int flags_nr, const char *subsystem,
int *active_options_p, const Common::Array<cmd_param_t> &cmdParams) {
- unsigned int i;
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
@@ -2293,7 +2292,7 @@ static int c_handle_config_update(const generic_config_flag_t *flags, int flags_
if (cmdParams.size() == 0)
handle_config_update(flags, flags_nr, subsystem, active_options_p, 0);
- for (i = 0; i < cmdParams.size(); i++)
+ for (uint i = 0; i < cmdParams.size(); i++)
handle_config_update(flags, flags_nr, subsystem, active_options_p, cmdParams[i].str);
return 0;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 73215a5d96..8b654c1388 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -2007,9 +2007,12 @@ static void _init_stack_base_with_selector(EngineState *s, Selector selector) {
s->stack_base[1] = NULL_REG;
}
+EngineState *g_EngineState = 0;
+
static EngineState *_game_run(EngineState *s, int restoring) {
EngineState *successor = NULL;
int game_is_finished = 0;
+ g_EngineState = s;
do {
s->_executionStackPosChanged = false;
run_vm(s, (successor || restoring) ? 1 : 0);
@@ -2038,6 +2041,7 @@ static EngineState *_game_run(EngineState *s, int restoring) {
script_free_vm_memory(s);
delete s;
s = successor;
+ g_EngineState = s;
if (script_abort_flag == SCRIPT_ABORT_WITH_REPLAY) {
sciprintf("Restarting with replay()\n");