diff --git a/builtin.c b/builtin.c index caceef30b..3d947c202 100644 --- a/builtin.c +++ b/builtin.c @@ -2268,9 +2268,20 @@ static int builtin_fg( wchar_t **argv ) since we want to know if this is an ambigous job specification or if this is an malformed job id */ - int pid = wcstol( argv[1], 0, 10 ); - j = job_get_from_pid( pid ); - if( j != 0 ) + wchar_t *endptr; + int pid; + int found_job = 0; + + errno = 0; + pid = wcstol( argv[1], &endptr, 10 ); + if( !( *endptr || errno ) ) + { + j = job_get_from_pid( pid ); + if( j ) + found_job = 1; + } + + if( found_job ) { sb_printf( sb_err, _( L"%ls: Ambiguous job\n" ), @@ -2283,6 +2294,7 @@ static int builtin_fg( wchar_t **argv ) argv[0], argv[1] ); } + builtin_print_help( argv[0], sb_err ); j=0; @@ -2291,9 +2303,11 @@ static int builtin_fg( wchar_t **argv ) else { wchar_t *end; - int pid = abs(wcstol( argv[1], &end, 10 )); + int pid; + errno = 0; + pid = abs(wcstol( argv[1], &end, 10 )); - if( *end ) + if( *end || errno ) { sb_printf( sb_err, BUILTIN_ERR_NOT_NUMBER, diff --git a/complete.c b/complete.c index a631eac2a..62b222b6b 100644 --- a/complete.c +++ b/complete.c @@ -1288,40 +1288,44 @@ static void complete_cmd( const wchar_t *cmd, else { path = env_get(L"PATH"); - path_cpy = wcsdup( path ); - - for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state ); - nxt_path != 0; - nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) + if( path ) { - nxt_completion = wcsdupcat2( nxt_path, - (nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"), - cmd, - 0 ); - if( ! nxt_completion ) - continue; - - al_init( &tmp ); - - if( expand_string( 0, - nxt_completion, - &tmp, - ACCEPT_INCOMPLETE | - EXECUTABLES_ONLY ) != EXPAND_ERROR ) + + path_cpy = wcsdup( path ); + + for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state ); + nxt_path != 0; + nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) { - for( i=0; ilast_loaded; history_count = d->count; past_end=1; - + // fwprintf( stderr, L"Destroy history mode \'%ls\'\n", mode_name ); - + if( history_last ) { history_save(); @@ -455,7 +453,6 @@ void history_destroy() &history_destroy_mode ); hash_destroy( &history_table ); - } diff --git a/input.c b/input.c index 256a37e74..2d57b84f1 100644 --- a/input.c +++ b/input.c @@ -1390,7 +1390,7 @@ static int interrupt_handler() /* Tell the reader an event occured */ - if( reader_interupted() ) + if( reader_interrupted() ) { /* Return 3, i.e. the character read by a Control-C. @@ -1654,7 +1654,7 @@ wint_t input_readch() /* Clear the interrupted flag */ - reader_interupted(); + reader_interrupted(); /* Search for sequence in various mapping tables diff --git a/reader.c b/reader.c index 2bfa470cf..07084eaf1 100644 --- a/reader.c +++ b/reader.c @@ -287,7 +287,7 @@ static pid_t original_pid; /** This variable is set to true by the signal handler when ^C is pressed */ -static int interupted=0; +static int interrupted=0; /** Original terminal mode when fish was started @@ -403,8 +403,8 @@ void reader_handle_int( int sig ) c->skip=1; c=c->outer; } - interupted = 1; - + interrupted = 1; + } wchar_t *reader_current_filename() @@ -504,11 +504,11 @@ static void remove_duplicates( array_list_t *l ) } -int reader_interupted() +int reader_interrupted() { - int res=interupted; + int res=interrupted; if( res ) - interupted=0; + interrupted=0; return res; } @@ -574,10 +574,7 @@ static void calc_prompt() */ if( data->exec_prompt ) { - - al_foreach( &prompt_list, &free ); - al_truncate( &prompt_list, 0 ); - + if( data->prompt ) { proc_push_interactive( 0 ); @@ -591,17 +588,20 @@ static void calc_prompt() } proc_pop_interactive(); } - + data->exec_prompt = 0; reader_write_title(); - + sb_clear( &data->prompt_buff ); for( i=0; iprompt_buff, (wchar_t *)al_get( &prompt_list, i ) ); } - + + al_foreach( &prompt_list, &free ); + al_truncate( &prompt_list, 0 ); + } } @@ -1287,7 +1287,7 @@ static void reader_interactive_init() /* Loop until we are in the foreground. */ while (tcgetpgrp( 0 ) != shell_pgid) { - kill (- shell_pgid, SIGTTIN); + killpg( shell_pgid, SIGTTIN); } /* Put ourselves in our own process group. */ @@ -1373,8 +1373,6 @@ void reader_replace_current_token( wchar_t *new_token ) if( !begin || !end ) return; -// fwprintf( stderr, L"%d %d, %d\n", begin-data->buff, end-data->buff, data->buff_len ); - /* Make new string */ @@ -1915,7 +1913,7 @@ void reader_set_test_function( int (*f)( wchar_t * ) ) static void reader_super_highlight_me_plenty( int *color, int match_highlight_pos, array_list_t *error ) { data->highlight_func( data->buff, color, match_highlight_pos, error ); - if( wcslen(data->search_buff) ) + if( data->search_buff && wcslen(data->search_buff) ) { wchar_t * match = wcsstr( data->buff, data->search_buff ); if( match ) @@ -2093,6 +2091,7 @@ wchar_t *reader_readline() while( 1 ) { c=input_readch(); + if( ( (!wchar_private(c))) && (c>31) && (c != 127) ) { if( can_read(0) ) diff --git a/reader.h b/reader.h index 2c6c0c1f7..9bd0223c4 100644 --- a/reader.h +++ b/reader.h @@ -95,10 +95,10 @@ void reader_set_buffer( wchar_t *b, int p ); int reader_get_cursor_pos(); /** - Return the value of the interupted flag, which is set by the sigint + Return the value of the interrupted flag, which is set by the sigint handler, and clear it if it was set. */ -int reader_interupted(); +int reader_interrupted(); /** Read one line of input. Before calling this function, reader_push() @@ -158,7 +158,7 @@ int exit_status(); void reader_replace_current_token( wchar_t *new_token ); /** - The readers interupt signal handler. Cancels all currently running blocks. + The readers interrupt signal handler. Cancels all currently running blocks. */ void reader_handle_int( int signal );