예제 #1
0
std::vector<source_file> find_sources(const std::string& base_path, const std::function<bool(std::string)>& predicate)
{
	std::vector<source_file> sources;
	find_sources(base_path, {}, predicate, sources);

	return std::move(sources);
}
예제 #2
0
void find_sources(const std::string& base_path, const std::string& path, const std::function<bool(std::string)>& predicate, std::vector<source_file>& sources)
{
	auto abs_path = base_path;

	if(!path.empty())
		abs_path += "/" + path;

	auto d = opendir(abs_path.c_str());
	if(d)
	{
		while (auto dir = readdir(d))
		{
			std::string name = dir->d_name;
			if(dir->d_type == DT_DIR)
			{
				if(name == "." || name == "..")
					continue;

				auto rel_path = name;
				if(!path.empty())
					rel_path = path + "/" + name;

				find_sources(base_path, rel_path, predicate, sources);
			}
			else if(dir->d_type == DT_REG)
			{
				if(predicate(name))
				{
					auto rel_source = name;
					if(!path.empty())
						rel_source = path + "/" + name;

					sources.push_back({name, path});
				}
			}
		}
		closedir(d);
	}
}
예제 #3
0
int *topo_sort(){
	int *Del = (int *)malloc(n*sizeof(int));
	memset(Del, FALSE, n*sizeof(int));

	int *Din = find_din();				// find in-degree of all vertices

	int *Ts = (int *)malloc(n*sizeof(int));		// the topological order
	memset(Ts, 0, n*sizeof(int));

	vlist *S = find_sources();
	int i = 1;
	int s;
	while(S != NULL){
		s = S->v;
		S = S->next;	// remove s from S
		Ts[s] = i;
		i++;
		Del[s] = TRUE;
		// loop through all neighbors of s;
		vlist *runner = G[s];
		int v;
		while(runner != NULL){
			v = runner->v;
			Din[v] --;
			if(Din[v] == 0){
				// add v to S
				vlist *node = malloc(sizeof(vlist));
				node->v = v;
				node->next = S;
				S = node;
			}		
			runner = runner->next;
		}
	}
	return Ts;

}
예제 #4
0
void rpm_locate_sources(const char *directory)
{
        /* TODO: Ensure directory name matches, need non-relative paths.. */
        find_sources(directory, &rpm_is_package);
}