diff --git a/FishsFish.xcodeproj/project.pbxproj b/FishsFish.xcodeproj/project.pbxproj index feefbbd95..16cd92eac 100644 --- a/FishsFish.xcodeproj/project.pbxproj +++ b/FishsFish.xcodeproj/project.pbxproj @@ -227,7 +227,7 @@ /* Begin PBXLegacyTarget section */ D0A084F713B3AC130099B651 /* FishsFish */ = { isa = PBXLegacyTarget; - buildArgumentsString = "-f Makefile.cpp -k ${ACTION}"; + buildArgumentsString = "-k ${ACTION}"; buildConfigurationList = D0A084FA13B3AC130099B651 /* Build configuration list for PBXLegacyTarget "FishsFish" */; buildPhases = ( ); diff --git a/env.cpp b/env.cpp index b84e08d6c..447e017ab 100644 --- a/env.cpp +++ b/env.cpp @@ -1589,6 +1589,97 @@ void env_get_names( array_list_t *l, int flags ) hash_destroy( &names ); } + +/** + Function used with hash_foreach to insert keys of one table into + a set::set +*/ +static void add_key_to_string_set( void *key, + void *data, + void *aux ) +{ + var_entry_t *e = (var_entry_t *)data; + if( ( e->exportv && get_names_show_exported) || + ( !e->exportv && get_names_show_unexported) ) + { + std::set *names = (std::set *)aux; + const wchar_t *keyStr = (const wchar_t *)key; + names->insert(keyStr); + } +} + +wcstring_list_t env_get_names( int flags ) +{ + wcstring_list_t result; + std::set names; + int show_local = flags & ENV_LOCAL; + int show_global = flags & ENV_GLOBAL; + int show_universal = flags & ENV_UNIVERSAL; + + env_node_t *n=top; + + + get_names_show_exported = + flags & ENV_EXPORT|| (!(flags & ENV_UNEXPORT)); + get_names_show_unexported = + flags & ENV_UNEXPORT|| (!(flags & ENV_EXPORT)); + + if( !show_local && !show_global && !show_universal ) + { + show_local =show_universal = show_global=1; + } + + if( show_local ) + { + while( n ) + { + if( n == global_env ) + break; + + hash_foreach2( &n->env, + add_key_to_string_set, + &names ); + + if( n->new_scope ) + break; + else + n = n->next; + + } + } + + if( show_global ) + { + hash_foreach2( &global_env->env, + add_key_to_string_set, + &names ); + + if( get_names_show_unexported ) { + result.insert(result.end(), env_electric.begin(), env_electric.end()); + } + + if( get_names_show_exported ) + { + result.push_back(L"COLUMNS"); + result.push_back(L"LINES"); + } + + } + + if( show_universal ) + { + + wcstring_list_t uni_list; + env_universal_get_names2(uni_list, + get_names_show_exported, + get_names_show_unexported); + names.insert(uni_list.begin(), uni_list.end()); + } + + result.insert(result.end(), names.begin(), names.end()); + return result; +} + /** Function used by env_export_arr to iterate over hashtable of variables */ diff --git a/env.h b/env.h index f7c57b534..fec0e9055 100644 --- a/env.h +++ b/env.h @@ -138,6 +138,7 @@ char **env_export_arr( int recalc ); Insert all variable names into l. These are not copies of the strings and should not be freed after use. */ void env_get_names( array_list_t *l, int flags ); +wcstring_list_t env_get_names( int flags ); /** Update the PWD variable diff --git a/function.cpp b/function.cpp index a9e1f6196..7deadfa26 100644 --- a/function.cpp +++ b/function.cpp @@ -150,20 +150,20 @@ static int load( const wchar_t *name ) */ static void autoload_names( array_list_t *out, int get_hidden ) { - int i; + size_t i; - array_list_t path_list; const wchar_t *path_var = env_get( L"fish_function_path" ); if( ! path_var ) return; - al_init( &path_list ); + wcstring_list_t path_list; - tokenize_variable_array( path_var, &path_list ); - for( i=0; iprompt.size() ) { proc_push_interactive( 0 ); - if( exec_subshell( data->prompt.c_str(), &prompt_list ) == -1 ) + if( exec_subshell2( data->prompt.c_str(), prompt_list ) == -1 ) { /* If executing the prompt fails, make sure we at least don't print any junk */ - al_foreach( &prompt_list, &free ); - al_destroy( &prompt_list ); - al_init( &prompt_list ); + prompt_list.clear(); } proc_pop_interactive(); } @@ -700,15 +697,11 @@ static void exec_prompt() data->prompt_buff.resize(0); - for( i = 0; i < al_get_count( &prompt_list ); i++ ) + for( i = 0; i < prompt_list.size(); i++ ) { - if (i > 0) data->prompt_buff += L"\n"; - data->prompt_buff += (wchar_t *)al_get( &prompt_list, i ); - } - - al_foreach( &prompt_list, &free ); - al_destroy( &prompt_list ); - + if (i > 0) data->prompt_buff += L'\n'; + data->prompt_buff += prompt_list.at(i); + } } void reader_init()