about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-18 21:10:03 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-18 21:10:03 +0000
commit46560cdb5077e459dabcb79081eb5ae3e185c0af (patch)
treef8b776789e7106ff490eddff6de75bbe55175fd4 /src/engine
parent9425cbef579fcce696468c3b4118e64f9d6232d3 (diff)
downloadzcatch-46560cdb5077e459dabcb79081eb5ae3e185c0af.tar.gz
zcatch-46560cdb5077e459dabcb79081eb5ae3e185c0af.zip
added exec command and added circular execution checking
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/e_console.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/engine/e_console.c b/src/engine/e_console.c
index 47725744..c45cf66f 100644
--- a/src/engine/e_console.c
+++ b/src/engine/e_console.c
@@ -225,7 +225,7 @@ void console_execute_line(const char *str)
 	console_execute_line_stroked(1, str);
 }
 
-void console_execute_file(const char *filename)
+static void console_execute_file_real(const char *filename)
 {
 	IOHANDLE file;
 	file = io_open(filename, IOFLAG_READ);
@@ -247,11 +247,48 @@ void console_execute_file(const char *filename)
 		dbg_msg("console", "failed to open '%s'", filename);
 }
 
-static void echo_command(void *result, void *user_data)
+struct exec_file
+{
+	const char *filename;
+	struct exec_file *next;
+};
+
+void console_execute_file(const char *filename)
+{
+	static struct exec_file *first = 0;
+	struct exec_file this;
+	struct exec_file *cur;
+	struct exec_file *prev;
+
+	/* make sure that this isn't being executed already */	
+	for(cur = first; cur; cur = cur->next)
+		if(strcmp(filename, cur->filename) == 0)
+			return;
+	
+	/* push this one to the stack */
+	prev = first;
+	this.filename = filename;
+	this.next = first;
+	first = &this;
+	
+	/* execute file */
+	console_execute_file_real(filename);
+	
+	/* pop this one from the stack */
+	first = prev;
+}
+
+static void con_echo(void *result, void *user_data)
 {
 	console_print(console_arg_string(result, 0));
 }
 
+static void con_exec(void *result, void *user_data)
+{
+	console_execute_file(console_arg_string(result, 0));
+
+}
+
 
 typedef struct 
 {
@@ -295,7 +332,8 @@ static void str_variable_command(void *result, void *user_data)
 
 void console_init()
 {
-	MACRO_REGISTER_COMMAND("echo", "r", echo_command, 0x0);
+	MACRO_REGISTER_COMMAND("echo", "r", con_echo, 0x0);
+	MACRO_REGISTER_COMMAND("exec", "r", con_exec, 0x0);
 
 	#define MACRO_CONFIG_INT(name,def,min,max) { static INT_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?i", int_variable_command, &data) }
 	#define MACRO_CONFIG_STR(name,len,def) { static STR_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?r", str_variable_command, &data) }