Clean up exec_subshell, removing al_list from it

This commit is contained in:
ridiculousfish 2012-02-07 23:35:41 -08:00
parent 6a31457c6d
commit 5f686ebb47
9 changed files with 26 additions and 34 deletions

View file

@ -301,7 +301,7 @@ bool autoload_t::locate_file_and_maybe_load_it( const wcstring &cmd, bool really
/* If we have a script, either built-in or a file source, then run it */
if (really_load && has_script_source)
{
if( exec_subshell( script_source.c_str(), 0 ) == -1 )
if( exec_subshell( script_source) == -1 )
{
/*
Do nothing on failiure

View file

@ -193,7 +193,7 @@ wcstring builtin_help_get( parser_t &parser, const wchar_t *name )
wcstring out;
const wcstring name_esc = escape_string(name, 1);
const wcstring cmd = format_string(L"__fish_print_help %ls", name_esc.c_str());
if( exec_subshell2( cmd, lst ) >= 0 )
if( exec_subshell( cmd, lst ) >= 0 )
{
for( size_t i=0; i<lst.size(); i++ )
{

View file

@ -270,7 +270,7 @@ static int condition_test( const wchar_t *condition )
if (test_res == CC_NOT_TESTED )
{
test_res = exec_subshell( condition, 0 )?CC_FALSE:CC_TRUE;
test_res = exec_subshell( condition)?CC_FALSE:CC_TRUE;
hash_put( condition_cache, condition, test_res );
/*
@ -946,7 +946,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &co
since apropos is only called once.
*/
wcstring_list_t list;
if( exec_subshell2( lookup_cmd, list ) != -1 )
if( exec_subshell( lookup_cmd, list ) != -1 )
{
/*

View file

@ -1705,23 +1705,8 @@ void exec( parser_t &parser, job_t *j )
}
int exec_subshell2( const wcstring &cmd, std::vector<wcstring> &outputs )
{
array_list_t lst;
al_init(&lst);
int result = exec_subshell(cmd.c_str(), &lst);
int i, max = al_get_count(&lst);
for (i=0; i < max; i++) {
wchar_t *tmp = (wchar_t *)al_get(&lst, i);
outputs.push_back(tmp);
free(tmp);
}
al_destroy(&lst);
return result;
}
int exec_subshell( const wchar_t *cmd,
array_list_t *lst )
static int exec_subshell_internal( const wcstring &cmd, wcstring_list_t *lst )
{
char *begin, *end;
char z=0;
@ -1730,7 +1715,6 @@ int exec_subshell( const wchar_t *cmd,
io_data_t *io_buffer;
char sep=0;
CHECK( cmd, -1 );
const env_var_t ifs = env_get_string(L"IFS");
if( ! ifs.missing_or_empty() )
@ -1783,7 +1767,7 @@ int exec_subshell( const wchar_t *cmd,
wchar_t *el = str2wcs( begin );
if( el )
{
al_push( lst, el );
lst->push_back(el);
}
else
{
@ -1801,7 +1785,7 @@ int exec_subshell( const wchar_t *cmd,
el = str2wcs( begin );
if( el )
{
al_push( lst, el );
lst->push_back(el);
}
else
{
@ -1817,3 +1801,13 @@ int exec_subshell( const wchar_t *cmd,
return status;
}
int exec_subshell( const wcstring &cmd, std::vector<wcstring> &outputs )
{
return exec_subshell_internal(cmd, &outputs);
}
__warn_unused int exec_subshell( const wcstring &cmd )
{
return exec_subshell_internal(cmd, NULL);
}

8
exec.h
View file

@ -50,14 +50,12 @@ void exec( parser_t &parser, job_t *j );
proc_gfet_last_status will not be changed.
\param cmd the command to execute
\param l The list to insert output into.If \c l is zero, the output will be discarded.
\param outputs The list to insert output into.
\return the status of the last job to exit, or -1 if en error was encountered.
*/
__warn_unused int exec_subshell( const wchar_t *cmd,
array_list_t *l );
__warn_unused int exec_subshell2( const wcstring &cmd, std::vector<wcstring> &outputs );
__warn_unused int exec_subshell(const wcstring &cmd, std::vector<wcstring> &outputs );
__warn_unused int exec_subshell(const wcstring &cmd );
/**

View file

@ -1262,7 +1262,7 @@ static int expand_cmdsubst( parser_t &parser, const wcstring &input, std::vector
const wcstring subcmd(paran_begin + 1, paran_end-paran_begin - 1);
if( exec_subshell2( subcmd, sub_res) == -1 )
if( exec_subshell( subcmd, sub_res) == -1 )
{
parser.error( CMDSUBST_ERROR, -1, L"Unknown error while evaulating command substitution" );
return 0;

View file

@ -126,7 +126,7 @@ void kill_add( wchar_t *str )
if (cmd != NULL)
{
if( exec_subshell( cmd, 0 ) == -1 )
if( exec_subshell( cmd) == -1 )
{
/*
Do nothing on failiure
@ -224,7 +224,7 @@ static void kill_check_x_buffer()
wcstring cmd = L"xsel -t 500 -b";
wcstring new_cut_buffer=L"";
wcstring_list_t list;
if( exec_subshell2( cmd, list ) != -1 )
if( exec_subshell( cmd, list ) != -1 )
{
for( i=0; i<list.size(); i++ )

View file

@ -685,7 +685,7 @@ void reader_write_title()
wcstring_list_t lst;
proc_push_interactive(0);
if( exec_subshell2( title, lst ) != -1 )
if( exec_subshell( title, lst ) != -1 )
{
size_t i;
if( lst.size() > 0 )
@ -715,7 +715,7 @@ static void exec_prompt()
{
proc_push_interactive( 0 );
if( exec_subshell2( data->prompt.c_str(), prompt_list ) == -1 )
if( exec_subshell( data->prompt.c_str(), prompt_list ) == -1 )
{
/* If executing the prompt fails, make sure we at least don't print any junk */
prompt_list.clear();

View file

@ -370,7 +370,7 @@ static wchar_t *complete_get_desc_suffix_internal( const wchar_t *suff_orig )
wcstring_list_t lst;
wcstring desc;
if( exec_subshell2( cmd, lst ) != -1 )
if( exec_subshell( cmd, lst ) != -1 )
{
if( lst.size()>0 )
{