From 84aa702ff8b66f883e9ac5792b26d4e9d0760573 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 22 Nov 2010 20:20:33 +0000 Subject: [script] Allow "exit" to exit a script Signed-off-by: Michael Brown --- src/image/script.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src/image') diff --git a/src/image/script.c b/src/image/script.c index ba098c2c1..f9d5a3939 100644 --- a/src/image/script.c +++ b/src/image/script.c @@ -99,23 +99,20 @@ static int process_script ( int ( * process_line ) ( const char *line ), } /** - * Terminate script processing if line processing failed + * Terminate script processing on shell exit or command failure * * @v rc Line processing status * @ret terminate Terminate script processing */ -static int terminate_on_failure ( int rc ) { - return ( rc != 0 ); -} +static int terminate_on_exit_or_failure ( int rc ) { -/** - * Terminate script processing if line processing succeeded - * - * @v rc Line processing status - * @ret terminate Terminate script processing - */ -static int terminate_on_success ( int rc ) { - return ( rc == 0 ); + /* Check and consume exit flag */ + if ( shell_exit ) { + shell_exit = 0; + return 1; + } + + return ( rc != 0 ); } /** @@ -164,7 +161,7 @@ static int script_exec ( struct image *image ) { script = image; /* Process script */ - rc = process_script ( script_exec_line, terminate_on_failure ); + rc = process_script ( script_exec_line, terminate_on_exit_or_failure ); /* Restore saved state, re-register image, and return */ script_offset = saved_offset; @@ -252,6 +249,16 @@ static int goto_find_label ( const char *line ) { return 0; } +/** + * Terminate script processing when label is found + * + * @v rc Line processing status + * @ret terminate Terminate script processing + */ +static int terminate_on_label_found ( int rc ) { + return ( rc == 0 ); +} + /** * "goto" command * @@ -280,7 +287,7 @@ static int goto_exec ( int argc, char **argv ) { /* Find label */ saved_offset = script_offset; if ( ( rc = process_script ( goto_find_label, - terminate_on_success ) ) != 0 ) { + terminate_on_label_found ) ) != 0 ) { script_offset = saved_offset; return rc; } -- cgit v1.2.3-55-g7522