ClienteTFG/read_uses.cpp

37 lines
950 B
C++
Raw Normal View History

2020-05-08 12:42:02 +02:00
#include "read_uses.h"
read_uses::read_uses(std::string name)
{
size_t pos=name.find("/");
if(pos==std::string::npos){
this->short_name=name;
}else{
this->short_name=name.substr(pos, name.size());
}
this->file=std::ifstream("/etc/portage/package.use/"+this->short_name, std::ifstream::in);
this->exist = file.good();
}
2020-05-13 00:56:26 +02:00
bool read_uses::exist_file(){
return this->exist;
}
2020-05-08 12:42:02 +02:00
std::string* read_uses::get_uses(){
std::string *ret=nullptr;
if(this->exist){
ret=new std::string;
std::string line;
while(std::getline(file, line)){
std::string no_coment=line.substr(0,line.find("#"));
std::size_t found=no_coment.find(this->short_name);
if(found!=std::string::npos){
found=no_coment.find(this->short_name);
if(found!=std::string::npos){
*ret=no_coment.substr(0, no_coment.length());
}
}
}
}
return ret;
}