Exemplo n.º 1
0
void exec_stream_t::start( std::string const & program, exec_stream_t::next_arg_t & next_arg )
{
    std::string arguments;
    while( std::string const * arg=next_arg.next() ) {
        if( arg->find_first_of( " \t\"" )!=std::string::npos ) {
            arguments+=" \"";
            std::string::size_type cur=0;
            while( cur<arg->size() ) {
                std::string::size_type next=arg->find( '"', cur );
                if( next==std::string::npos ) {
                    next=arg->size();
                    arguments.append( *arg, cur, next-cur );
                    cur=next;
                }else {
                    arguments.append( *arg, cur, next-cur );
                    arguments+="\\\"";
                    cur=next+1;
                }
            }
            arguments+="\"";
        }else {
            arguments+=" "+*arg;
        }
    }
    start( program, arguments );
}
Exemplo n.º 2
0
void exec_stream_t::impl_t::split_args( std::string const & program, exec_stream_t::next_arg_t & next_arg )
{
    typedef std::vector< std::size_t > arg_sizes_t;
    arg_sizes_t arg_sizes;
    
    m_child_args.new_data( program.size()+1 );
    std::string::traits_type::copy( m_child_args.data(), program.c_str(), program.size()+1 );
    arg_sizes.push_back( program.size()+1 );
    
    while( std::string const * s=next_arg.next() ) {
        m_child_args.append_data( s->c_str(), s->size()+1 );
        arg_sizes.push_back( s->size()+1 );
    }
    
    char ** argp_end=m_child_argp.new_data( arg_sizes.size()+1 );
    char * argp=m_child_args.data();
    for( arg_sizes_t::iterator i=arg_sizes.begin(); i!=arg_sizes.end(); ++i ) {
        *argp_end=argp;
        argp+=*i;
        ++argp_end;
    }
    *argp_end=0;
}