From ddcb84aa07607bbd274edb89ddc4371d8d7aa27f Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 25 Oct 2005 21:03:52 +1000 Subject: [PATCH] Fix problem bug breaking completion in commands with multiple subshells darcs-hash:20051025110352-ac50b-fff319ddcbafb722b9bc3c61aa1b250b290716a5.gz --- common.c | 2 +- common.h | 2 +- complete.c | 6 +++--- env.c | 10 ++++++++-- expand.c | 2 +- expand.h | 2 +- highlight.c | 5 +++-- init/fish_function.fish | 2 +- reader.c | 34 ++++++++++++++++++++-------------- 9 files changed, 39 insertions(+), 26 deletions(-) diff --git a/common.c b/common.c index d950f4a01..ce7a3588a 100644 --- a/common.c +++ b/common.c @@ -911,7 +911,7 @@ void debug( int level, wchar_t *msg, ... ) } putwc( L'\n', stderr ); - + sb_destroy( &sb ); } wchar_t *escape( const wchar_t *in, diff --git a/common.h b/common.h index 60690ba4d..3954f505f 100644 --- a/common.h +++ b/common.h @@ -270,7 +270,7 @@ wchar_t *escape( const wchar_t *in, counterparts. Also optionally change the wildcards, the tilde character and a few more into constants which are defined in a private use area of Unicode. This assumes wchar_t is a unicode - character. character set. + character set. The result must be free()d. The original string is not modified. If an invalid sequence is specified, 0 is returned. diff --git a/complete.c b/complete.c index 6c39d244e..8088cfe08 100644 --- a/complete.c +++ b/complete.c @@ -1765,10 +1765,10 @@ static void complete_param_expand( wchar_t *str, } else comp_str = str; - -// fwprintf( stderr, L"expand_string( \"%ls\", [list], ACCEPT_INCOMPLETE | %ls )\n", comp_str, do_file?L"0":L"EXPAND_SKIP_WILDCARDS" ); - expand_string( wcsdup(comp_str), comp_out, ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) ); +// fwprintf( stderr, L"expand_string( \"%ls\", [list], EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls )\n", comp_str, do_file?L"0":L"EXPAND_SKIP_WILDCARDS" ); + + expand_string( wcsdup(comp_str), comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) ); } /** diff --git a/env.c b/env.c index e4688cfb2..a58f75f8c 100644 --- a/env.c +++ b/env.c @@ -388,8 +388,12 @@ void env_init() pw = getpwuid( getuid() ); - uname = str2wcs( pw->pw_name ); - env_set( L"USER", uname, ENV_GLOBAL | ENV_EXPORT ); + if( pw ) + { + uname = str2wcs( pw->pw_name ); + env_set( L"USER", uname, ENV_GLOBAL | ENV_EXPORT ); + free( uname ); + } env_universal_init( env_get( L"FISHD_SOKET_DIR"), env_get( L"USER" ), @@ -410,6 +414,8 @@ void env_destroy() env_pop(); hash_destroy( &env_read_only ); + + hash_destroy( &env_electric ); hash_foreach( global, &clear_hash_entry ); hash_destroy( global ); diff --git a/expand.c b/expand.c index f12c36e0a..4236d2ab1 100644 --- a/expand.c +++ b/expand.c @@ -1328,6 +1328,7 @@ int expand_string( wchar_t *str, if( (pos == str) || ( *(pos-1) != L'\\' ) ) { error( SUBSHELL_ERROR, L"Subshells not allowed", -1 ); + free( str ); al_destroy( &list1 ); al_destroy( &list2 ); return 0; @@ -1505,7 +1506,6 @@ wchar_t *expand_one( wchar_t *string, int flags ) res = expand_string( string, &l, flags ); if( !res ) { - free( string ); one = 0; } else diff --git a/expand.h b/expand.h index 3c650343d..038519c97 100644 --- a/expand.h +++ b/expand.h @@ -162,7 +162,7 @@ wchar_t *expand_escape_variable( const wchar_t *in ); wchar_t *expand_tilde(wchar_t *in); /** - Locate the last subshell in the specified string. + Locate the first subshell in the specified string. \param in the string to search for subshells \param begin the starting paranthesis of the subshell diff --git a/highlight.c b/highlight.c index e3783eda9..51d5c8853 100644 --- a/highlight.c +++ b/highlight.c @@ -357,7 +357,7 @@ void highlight_shell( wchar_t * buff, /* Locate and syntax highlight subshells recursively */ - + wchar_t *buffcpy = wcsdup( buff ); wchar_t *subpos=buffcpy; int done=0; @@ -386,8 +386,9 @@ void highlight_shell( wchar_t * buff, break; subpos = end+1; + } - free( buffcpy ); + free( buffcpy); last_val=0; diff --git a/init/fish_function.fish b/init/fish_function.fish index 7cb7e04be..97d4c6b1e 100644 --- a/init/fish_function.fish +++ b/init/fish_function.fish @@ -942,7 +942,7 @@ function psub -d "Read from stdin into a file and output the filename. Remove th end if not status --is-command-substitution - echo psub: Not inside of command substitution + echo psub: Not inside of command substitution >&2 return end diff --git a/reader.c b/reader.c index f577a666d..85dbaf407 100644 --- a/reader.c +++ b/reader.c @@ -1548,9 +1548,9 @@ void reader_sanity_check() void reader_current_subshell_extent( wchar_t **a, wchar_t **b ) { - wchar_t *buffcpy = wcsdup( data->buff ); wchar_t *begin, *end; - + wchar_t *pos; + if( a ) *a=0; if( b ) @@ -1559,35 +1559,41 @@ void reader_current_subshell_extent( wchar_t **a, wchar_t **b ) if( !data ) return; + pos = data->buff; + while( 1 ) { int bc, ec; - - if( expand_locate_subshell( buffcpy, + + if( expand_locate_subshell( pos, &begin, &end, 1 ) <= 0) { - begin=buffcpy; - end = buffcpy + wcslen(data->buff); + begin=data->buff; + end = data->buff + wcslen(data->buff); break; } - bc = begin-buffcpy; - ec = end-buffcpy; + + if( !end ) + { + end = data->buff + wcslen(data->buff); + } + + bc = begin-data->buff; + ec = end-data->buff; + if(( bc < data->buff_pos ) && (ec >= data->buff_pos) ) { begin++; - - //fwprintf( stderr, L"Subshell!\n" ); break; } - *begin=0; + pos = end+1; } if( a ) - *a = data->buff + (begin-buffcpy); + *a = begin; if( b ) - *b = data->buff + (end-buffcpy); - free( buffcpy ); + *b = end; } static void reader_current_job_or_process_extent( wchar_t **a,