From 5f686ebb478b461c3044261a84fc347072c1ff07 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 7 Feb 2012 23:35:41 -0800 Subject: [PATCH] Clean up exec_subshell, removing al_list from it --- autoload.cpp | 2 +- builtin.cpp | 2 +- complete.cpp | 4 ++-- exec.cpp | 32 +++++++++++++------------------- exec.h | 8 +++----- expand.cpp | 2 +- kill.cpp | 4 ++-- reader.cpp | 4 ++-- wildcard.cpp | 2 +- 9 files changed, 26 insertions(+), 34 deletions(-) diff --git a/autoload.cpp b/autoload.cpp index f7968ac33..2cbce79b3 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -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 diff --git a/builtin.cpp b/builtin.cpp index c1168ae56..d505af6a8 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -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 &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 ) { /* diff --git a/exec.cpp b/exec.cpp index adf019aa5..db81d76c4 100644 --- a/exec.cpp +++ b/exec.cpp @@ -1705,23 +1705,8 @@ void exec( parser_t &parser, job_t *j ) } -int exec_subshell2( const wcstring &cmd, std::vector &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 &outputs ) +{ + return exec_subshell_internal(cmd, &outputs); +} + +__warn_unused int exec_subshell( const wcstring &cmd ) +{ + return exec_subshell_internal(cmd, NULL); +} diff --git a/exec.h b/exec.h index 17d29157f..ddbe2dcb0 100644 --- a/exec.h +++ b/exec.h @@ -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 &outputs ); +__warn_unused int exec_subshell(const wcstring &cmd, std::vector &outputs ); +__warn_unused int exec_subshell(const wcstring &cmd ); /** diff --git a/expand.cpp b/expand.cpp index 846c155e2..da1a13c15 100644 --- a/expand.cpp +++ b/expand.cpp @@ -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; diff --git a/kill.cpp b/kill.cpp index f766b03f9..76dcb24e0 100644 --- a/kill.cpp +++ b/kill.cpp @@ -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 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(); diff --git a/wildcard.cpp b/wildcard.cpp index 406a9aa46..aba13ae28 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -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 ) {