mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Additional migration to STL data structures
This commit is contained in:
parent
a6b3f6b5d4
commit
c18d177b8c
5 changed files with 107 additions and 24 deletions
|
@ -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 = (
|
||||
);
|
||||
|
|
91
env.cpp
91
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<wcstring>
|
||||
*/
|
||||
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<wcstring> *names = (std::set<wcstring> *)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<wcstring> 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
|
||||
*/
|
||||
|
|
1
env.h
1
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
|
||||
|
|
14
function.cpp
14
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; i<al_get_count( &path_list ); i++ )
|
||||
tokenize_variable_array2( path_var, path_list );
|
||||
for( i=0; i<path_list.size(); i++ )
|
||||
{
|
||||
wchar_t *ndir = (wchar_t *)al_get( &path_list, i );
|
||||
const wcstring &ndir_str = path_list.at(i);
|
||||
const wchar_t *ndir = (wchar_t *)ndir_str.c_str();
|
||||
DIR *dir = wopendir( ndir );
|
||||
if( !dir )
|
||||
continue;
|
||||
|
@ -189,8 +189,6 @@ static void autoload_names( array_list_t *out, int get_hidden )
|
|||
}
|
||||
closedir(dir);
|
||||
}
|
||||
al_foreach( &path_list, &free );
|
||||
al_destroy( &path_list );
|
||||
}
|
||||
|
||||
void function_init()
|
||||
|
|
21
reader.cpp
21
reader.cpp
|
@ -677,21 +677,18 @@ void reader_write_title()
|
|||
*/
|
||||
static void exec_prompt()
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
array_list_t prompt_list;
|
||||
al_init( &prompt_list );
|
||||
wcstring_list_t prompt_list;
|
||||
|
||||
if( data->prompt.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 );
|
||||
if (i > 0) data->prompt_buff += L'\n';
|
||||
data->prompt_buff += prompt_list.at(i);
|
||||
}
|
||||
|
||||
al_foreach( &prompt_list, &free );
|
||||
al_destroy( &prompt_list );
|
||||
|
||||
}
|
||||
|
||||
void reader_init()
|
||||
|
|
Loading…
Reference in a new issue