Simplify exec_subshell_internal

This commit is contained in:
ridiculousfish 2012-12-19 16:40:10 -08:00
parent 644607c29f
commit d5af389d2e

View file

@ -1418,8 +1418,6 @@ void exec(parser_t &parser, job_t *j)
static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst) static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst)
{ {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
char *begin, *end;
char z=0;
int prev_subshell = is_subshell; int prev_subshell = is_subshell;
int status, prev_status; int status, prev_status;
io_data_t *io_buffer; io_data_t *io_buffer;
@ -1462,41 +1460,31 @@ static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst)
is_subshell = prev_subshell; is_subshell = prev_subshell;
io_buffer->out_buffer_append(&z, 1); if (lst != NULL)
begin=end=io_buffer->out_buffer_ptr();
//REWRITEME
if (lst)
{ {
while (1) const char *begin = io_buffer->out_buffer_ptr();
const char *end = begin + io_buffer->out_buffer_size();
const char *cursor = begin;
while (cursor < end)
{ {
if (*end == 0) // Look for the next separator
const char *stop = (const char *)memchr(cursor, sep, end - cursor);
bool hit_separator = (stop != NULL);
if (! hit_separator)
{ {
assert(begin != NULL); // If it's not found, just use the end
if (begin != end) stop = end;
{
const wcstring el = str2wcstring(begin);
lst->push_back(el);
} }
io_buffer_destroy(io_buffer); // Stop now points at the first character we do not want to copy)
const wcstring wc = str2wcstring(cursor, stop - cursor);
lst->push_back(wc);
return status; // If we hit a separator, skip over it; otherwise we're at the end
} cursor = stop + (hit_separator ? 1 : 0);
else if (*end == sep)
{
*end=0;
const wcstring el = str2wcstring(begin);
lst->push_back(el);
begin = end+1;
}
end++;
} }
} }
io_buffer_destroy(io_buffer); io_buffer_destroy(io_buffer);
return status; return status;
} }