From 093cb71f91744bd4fe2b85ead3216a54f255e09c Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Wed, 26 Sep 2007 19:01:59 +1000 Subject: [PATCH] Fix bug in exit code that made the exit builtin exit even if there where running jobs if called directly from the commandline darcs-hash:20070926090159-75c98-2760c6c24e21fd14711c9ce3bef1b0890b495d65.gz --- reader.c | 127 ++++++++++++++++------------ share/functions/delete-or-exit.fish | 13 ++- 2 files changed, 83 insertions(+), 57 deletions(-) diff --git a/reader.c b/reader.c index 3dd86b69a..c52685da1 100644 --- a/reader.c +++ b/reader.c @@ -2150,6 +2150,68 @@ int exit_status() return end_loop; } +/** + This function is called when the main loop notices that end_loop + has been set while in interactive mode. It checks if it is ok to + exit. + */ + +static void handle_end_loop() +{ + job_t *j; + int job_count=0; + int is_breakpoint=0; + block_t *b; + + for( b = current_block; + b; + b = b->outer ) + { + if( b->type == BREAKPOINT ) + { + is_breakpoint = 1; + break; + } + } + + for( j=first_job; j; j=j->next ) + { + if( !job_is_completed(j) ) + { + job_count++; + break; + } + } + + if( !reader_exit_forced() && !data->prev_end_loop && job_count && !is_breakpoint ) + { + writestr(_( L"There are stopped jobs\n" )); + + reader_exit( 0, 0 ); + data->prev_end_loop=1; + } + else + { + if( !isatty(0) ) + { + /* + We already know that stdin is a tty since we're + in interactive mode. If isatty returns false, it + means stdin must have been closed. + */ + for( j = first_job; j; j=j->next ) + { + if( ! job_is_completed( j ) ) + { + job_signal( j, SIGHUP ); + } + } + } + } +} + + + /** Read interactively. Read input from stdin while providing editing facilities. @@ -2186,58 +2248,7 @@ static int read_i() if( data->end_loop) { - job_t *j; - int has_job=0; - int is_breakpoint=0; - block_t *b; - - for( b = current_block; - b; - b = b->outer ) - { - if( b->type == BREAKPOINT ) - { - is_breakpoint = 1; - break; - } - } - - for( j=first_job; j; j=j->next ) - { - if( !job_is_completed(j) ) - { - has_job = 1; - break; - } - } - - if( !reader_exit_forced() && !data->prev_end_loop && has_job && !is_breakpoint ) - { - writestr(_( L"There are stopped jobs\n" )); - - reader_exit( 0, 0 ); - data->prev_end_loop=1; - - repaint(); - } - else - { - if( !isatty(0) ) - { - /* - We already know that stdin is a tty since we're - in interactive mode. If isatty returns false, it - means stdin must have been closed. - */ - for( j = first_job; j; j=j->next ) - { - if( ! job_is_completed( j ) ) - { - job_signal( j, SIGHUP ); - } - } - } - } + handle_end_loop(); } else if( tmp ) { @@ -2247,9 +2258,16 @@ static int read_i() data->buff[data->buff_len]=L'\0'; reader_run_command( tmp ); free( tmp ); - - data->prev_end_loop=0; + if( data->end_loop) + { + handle_end_loop(); + } + else + { + data->prev_end_loop=0; + } } + } reader_pop(); @@ -2447,6 +2465,7 @@ wchar_t *reader_readline() case R_NULL: { + repaint(); break; } diff --git a/share/functions/delete-or-exit.fish b/share/functions/delete-or-exit.fish index d82bf2ac1..771a6bc3f 100644 --- a/share/functions/delete-or-exit.fish +++ b/share/functions/delete-or-exit.fish @@ -6,11 +6,18 @@ # function delete-or-exit + set -l cmd (commandline) - if test "$cmd" - commandline -f delete-char - else + + switch $cmd + + case '' exit 0 + + case '*' + commandline -f delete-char + end + end