[Scummvm-cvs-logs] SF.net SVN: scummvm:[40459] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon May 11 20:02:48 CEST 2009


Revision: 40459
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40459&view=rev
Author:   fingolfin
Date:     2009-05-11 18:02:48 +0000 (Mon, 11 May 2009)

Log Message:
-----------
SCI: Hook FreeSCI console commands into the ScummVM console (incomplete as of now, because printf output is not yet redirect to the GUI console)

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/console.h
    scummvm/trunk/engines/sci/engine/scriptconsole.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/scicore/sciconsole.h

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/console.cpp	2009-05-11 18:02:48 UTC (rev 40459)
@@ -33,6 +33,45 @@
 
 namespace Sci {
 
+extern EngineState *g_EngineState;
+
+class ConsoleFunc : public Common::Functor2<int, const char **, bool> {
+public:
+	ConsoleFunc(const ConCommand &func, const char *param) : _func(func), _param(param) {}
+
+	bool isValid() const { return _func != 0; }
+	bool operator()(int argc, const char **argv) const {
+#if 1
+		// FIXME: Evil hack: recreate the original input string
+		Common::String tmp = argv[0];
+		for (int i = 1; i < argc; ++i) {
+			tmp += ' ';
+			tmp += argv[i];
+		}
+		con_parse(g_EngineState, tmp.c_str());
+
+		return true;
+#else
+		Common::Array<cmd_param_t> cmdParams;
+		for (int i = 1; i < argc; ++i) {
+			cmd_param_t tmp;
+			tmp.str = argv[i];
+			// TODO: Convert argc/argv suitable, using _param
+			cmdParams.push_back(tmp);
+		}
+		assert(g_EngineState);
+		return !(*_func)(g_EngineState, cmdParams);
+#endif
+	}
+private:
+	EngineState *_s;
+	const ConCommand _func;
+	const char *_param;
+};
+
+
+
+
 Console::Console(SciEngine *vm) : GUI::Debugger() {
 	_vm = vm;
 
@@ -45,6 +84,11 @@
 Console::~Console() {
 }
 
+void Console::con_hook_command(ConCommand command, const char *name, const char *param, const char *description) {
+	DCmd_Register(name, new ConsoleFunc(command, param));
+}
+
+
 bool Console::cmdGetVersion(int argc, const char **argv) {
 	int ver = _vm->getVersion();
 

Modified: scummvm/trunk/engines/sci/console.h
===================================================================
--- scummvm/trunk/engines/sci/console.h	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/console.h	2009-05-11 18:02:48 UTC (rev 40459)
@@ -29,6 +29,7 @@
 #define SCI_CONSOLE_H
 
 #include "gui/debugger.h"
+#include "sci/scicore/sciconsole.h"
 
 namespace Sci {
 
@@ -39,6 +40,8 @@
 	Console(SciEngine *vm);
 	virtual ~Console();
 
+	void con_hook_command(ConCommand command, const char *name, const char *param, const char *description);
+
 private:
 	bool cmdGetVersion(int argc, const char **argv);
 	bool cmdSelectors(int argc, const char **argv);

Modified: scummvm/trunk/engines/sci/engine/scriptconsole.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/engine/scriptconsole.cpp	2009-05-11 18:02:48 UTC (rev 40459)
@@ -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 @@
 		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 @@
 }
 
 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 @@
 	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 @@
 		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 @@
 				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 @@
 	cmd->param = param;
 	cmd->description = description;
 
+	((SciEngine *)g_engine)->_console->con_hook_command(command, name, param, description);
+
 	return 0;
 }
 
@@ -664,7 +671,7 @@
 
 // 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_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 @@
 
 	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 @@
 		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;

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-11 18:02:48 UTC (rev 40459)
@@ -777,9 +777,9 @@
 
 	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 @@
 		}
 
 		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 @@
 };
 
 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_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_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 @@
 };
 
 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 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 @@
 	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;

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-11 18:02:48 UTC (rev 40459)
@@ -2007,9 +2007,12 @@
 	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 @@
 				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");

Modified: scummvm/trunk/engines/sci/scicore/sciconsole.h
===================================================================
--- scummvm/trunk/engines/sci/scicore/sciconsole.h	2009-05-11 18:02:27 UTC (rev 40458)
+++ scummvm/trunk/engines/sci/scicore/sciconsole.h	2009-05-11 18:02:48 UTC (rev 40459)
@@ -48,7 +48,7 @@
 
 union cmd_param_t {
 	int32 val;
-	char *str;
+	const char *str;
 	reg_t reg;
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list