Beispiel #1
0
std::string search_executable(tstring const& filename, tstring const& path)
{
    const bool filename_has_extension    = has_extension(filename);
    const bool filename_is_absolute_path = is_absolute(filename);
    
    const std::vector<std::string> extensions = get_executable_extensions();  
    
    if( ! filename_is_absolute_path ) {
        const std::vector<std::string> dirs = split(path, PATH_SEPARATOR);
        
        for(std::vector<std::string>::const_iterator ipath = dirs.begin(); ipath != dirs.end(); ++ipath ) {
            const std::string path1 = tinfra::path::join(*ipath, filename);
            if( filename_has_extension ) {
                if( is_executable(path1 ,extensions) )
                    return path1;
                continue;
            }
            std::string maybe_with_ext = find_variant(path1, extensions);
            if( ! maybe_with_ext.empty() )
                return maybe_with_ext;
        }
    } else if( ! filename_has_extension ) {
        return find_variant(filename.str(), extensions);
    } else {
        if( is_executable(filename, extensions) ) {
            return filename.str();
        }
    }
    return "";
}
Beispiel #2
0
std::string basename(tstring const& name)
{
    std::string::size_type p = name.find_last_of("/\\");
    if( p == tstring::npos ) {
        return name.str();
    } else {
        return std::string(name.data()+p+1, name.size()-p-1);
    }
}
Beispiel #3
0
void start_detached(tstring const& command, environment_t const* env)
{
    std::auto_ptr<subprocess> p = subprocess::create();
    p->set_stdout_mode(subprocess::NONE);
    p->set_stdin_mode(subprocess::NONE);
    p->set_stderr_mode(subprocess::NONE);
    
    if( env )
        p->set_environment(*env);
    p->start(command.str().c_str());
    p->detach();
}
Beispiel #4
0
std::string remove_all_extensions(tstring const& filename)
{
	const size_t last_slash = filename.find_last_of("\\/");
	const size_t last_dot = filename.find_first_of('.', last_slash);
	if( ( last_dot == tstring::npos ) ||
		( last_dot == filename.size() - 1 ) ) 
	{
		return filename.str();
	} else {
		tstring result = filename.substr(0, last_dot);
		return result.str();
	}
}
Beispiel #5
0
// TODO: move it to posix_common.sh
std::string search_executable(tstring const& filename, tstring const& path)
{
    if( is_absolute(filename) )
        if( is_executable(filename) )
            return filename.str();
    
    std::vector<std::string> dirs = split(path, PATH_SEPARATOR);
    
    for(std::vector<std::string>::const_iterator ipath = dirs.begin(); ipath != dirs.end(); ++ipath )
    {
        std::string result_name = tinfra::path::join(*ipath, filename);
        if( is_executable(result_name) ) {
            return result_name;
        }
    }
    return "";
}
Beispiel #6
0
test_fs_sandbox::test_fs_sandbox(tstring const& name):
	fs_sandbox(tinfra::local_fs()),
	name_(name.str()) 
{
    if( name_.size() > 0 ) {
        string real_path = path::join(top_srcdir, name_);
        if( !fs::exists(real_path) ) {
			const std::string error_message = (fmt("unable to find test resource %s (%s)") % name_ % real_path).str();
            throw std::logic_error(error_message);
        }
        
        fs::recursive_copy(real_path, fs_sandbox::path());
    } 
    orig_pwd_ = fs::pwd();
    fs::cd(fs_sandbox::path());
    TINFRA_TRACE(test_fs_sandbox_tracer, fmt("entering sandbox pwd='%s'") % fs_sandbox::path());
}
Beispiel #7
0
    id_type get_id_for_name(tstring const& name)
    {
        tinfra::guard instance_guard(instance_lock_);
        
        name_to_id_mapping_t::const_iterator i =  name_map_.find(name);
	if( i == name_map_.end() ) 
	{		
		id_type result_id = next_symbol_id_++;
		name_storage_t::const_iterator istr = name_storage_.insert(name_storage_.end(), name.str());
                
                tstring name_allocated(*istr);
		name_index_.push_back(istr);                
		name_map_[name_allocated] = result_id;
		return result_id;
	} 
	else 
	{
		return i->second;
	}
    }
Beispiel #8
0
 static void foo(tstring const& a)
 {
     std::string x = a.str();
 }