Browse Source

The forceline() and readline() can return executed command output (stdout). Fix issue #43.

git-svn-id: https://klish.googlecode.com/svn/trunk@293 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
49389e701e

+ 2 - 0
clish/clish_script_callback.c

@@ -155,6 +155,8 @@ bool_t clish_dryrun_callback(clish_shell_t * this,
 #ifdef DEBUG
 	fprintf(stderr, "DRY-RUN: %s\n", script);
 #endif /* DEBUG */
+	if (out)
+		*out = NULL;
 
 	return BOOL_TRUE;
 }

+ 3 - 3
clish/shell.h

@@ -319,11 +319,11 @@ clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * instance,
 int clish_shell_xml_read(clish_shell_t * instance, const char *filename);
 void clish_shell_help(clish_shell_t * instance, const char *line);
 bool_t clish_shell_execute(clish_shell_t * instance,
-	const clish_command_t * cmd, clish_pargv_t * pargv);
+	const clish_command_t * cmd, clish_pargv_t * pargv, char ** out);
 bool_t clish_shell_line(clish_shell_t * instance, const char *prompt,
 	const clish_command_t ** cmd, clish_pargv_t ** pargv, const char *str);
-bool_t clish_shell_forceline(clish_shell_t *instance, const char *line);
-bool_t clish_shell_readline(clish_shell_t *instance);
+bool_t clish_shell_forceline(clish_shell_t *instance, const char *line, char ** out);
+bool_t clish_shell_readline(clish_shell_t *instance, char ** out);
 void clish_shell_set_context(clish_shell_t * instance, const char *viewname);
 void clish_shell_dump(clish_shell_t * instance);
 void clish_shell_close(clish_shell_t * instance);

+ 2 - 2
clish/shell/shell_execute.c

@@ -181,7 +181,7 @@ void clish_shell_cleanup_script(void *script)
 /*----------------------------------------------------------- */
 bool_t
 clish_shell_execute(clish_shell_t * this,
-	const clish_command_t * cmd, clish_pargv_t * pargv)
+	const clish_command_t * cmd, clish_pargv_t * pargv, char ** out)
 {
 	bool_t result = BOOL_TRUE;
 	const char *builtin;
@@ -278,7 +278,7 @@ clish_shell_execute(clish_shell_t * this,
 		}
 	} else if (NULL != script) {
 		/* now get the client to interpret the resulting script */
-		result = this->client_hooks->script_fn(this, cmd, script, NULL);
+		result = this->client_hooks->script_fn(this, cmd, script, out);
 	}
 	pthread_cleanup_pop(1);
 

+ 1 - 1
clish/shell/shell_spawn.c

@@ -136,7 +136,7 @@ static bool_t _loop(clish_shell_t * this, bool_t is_thread)
 			/* only bother to read the next line if there hasn't been a script error */
 			if (this->state != SHELL_STATE_SCRIPT_ERROR) {
 				/* get input from the user */
-				running = clish_shell_readline(this);
+				running = clish_shell_readline(this, NULL);
 			}
 			if ((BOOL_FALSE == running) ||
 			    (this->state == SHELL_STATE_SCRIPT_ERROR)) {

+ 1 - 1
clish/shell/shell_startup.c

@@ -18,7 +18,7 @@ bool_t clish_shell_startup(clish_shell_t * this)
 	if (NULL != banner) {
 		tinyrl_printf(this->tinyrl, "%s\n", banner);
 	}
-	return clish_shell_execute(this, this->startup, NULL);
+	return clish_shell_execute(this, this->startup, NULL, NULL);
 }
 
 /*----------------------------------------------------------- */

+ 6 - 6
clish/shell/shell_tinyrl.c

@@ -398,7 +398,7 @@ bool_t clish_shell_line(clish_shell_t * this, const char *prompt,
 }
 
 /*-------------------------------------------------------- */
-bool_t clish_shell_execline(clish_shell_t *this, const char *line)
+bool_t clish_shell_execline(clish_shell_t *this, const char *line, char ** out)
 {
 	const clish_command_t *cmd;
 	char *prompt = NULL;
@@ -430,7 +430,7 @@ bool_t clish_shell_execline(clish_shell_t *this, const char *line)
 
 	/* execute the provided command */
 	if (running && cmd && pargv) {
-		if (BOOL_FALSE == clish_shell_execute(this, cmd, pargv)) {
+		if (BOOL_FALSE == clish_shell_execute(this, cmd, pargv, out)) {
 			if((!this->current_file && line) ||
 				(this->current_file &&
 				this->current_file->stop_on_error)) {
@@ -446,15 +446,15 @@ bool_t clish_shell_execline(clish_shell_t *this, const char *line)
 }
 
 /*-------------------------------------------------------- */
-bool_t clish_shell_forceline(clish_shell_t *this, const char *line)
+bool_t clish_shell_forceline(clish_shell_t *this, const char *line, char ** out)
 {
-	return clish_shell_execline(this, line);
+	return clish_shell_execline(this, line, out);
 }
 
 /*-------------------------------------------------------- */
-bool_t clish_shell_readline(clish_shell_t *this)
+bool_t clish_shell_readline(clish_shell_t *this, char ** out)
 {
-	return clish_shell_execline(this, NULL);
+	return clish_shell_execline(this, NULL, out);
 }
 
 /*-------------------------------------------------------- */