Commit 7a1852f9 authored by Roland Singer's avatar Roland Singer

* added function to include extern files from config

* implemented function to determind right path of included files
parent d1e1bd56
......@@ -69,9 +69,41 @@ bool mhwd::Config::readConfig(const Vita::string path) {
key = parts.front().trim().toLower();
value = parts.back().trim("\"").trim();
// Read in extern file
if (value.size() > 1 && value.substr(0, 1) == ">") {
ifstream file(getRightPath(value.substr(1)).c_str(), ios::in);
if (!file.is_open())
return false;
Vita::string line;
value.clear();
while (!file.eof()) {
getline(file, line);
size_t pos = line.find_first_of('#');
if (pos != string::npos)
line.erase(pos);
if (line.trim().empty())
continue;
value += " " + line.trim();
}
file.close();
value = value.trim();
// remove all multiple spaces
while (value.find(" ") != string::npos) {
value = value.replace(" ", " ");
}
}
if (key == "include") {
readConfig(value);
readConfig(getRightPath(value));
}
else if (key == "name") {
name = value;
......@@ -147,3 +179,14 @@ void mhwd::Config::addNewIDsGroup() {
IDsGroup group;
IDs.push_back(group);
}
Vita::string mhwd::Config::getRightPath(Vita::string str) {
str = str.trim();
if (str.size() <= 0 || str.substr(0, 1) == "/")
return str;
return path.substr(0, path.find_last_of('/')) + "/" + str;
}
......@@ -56,6 +56,7 @@ namespace mhwd {
bool readConfig(const Vita::string path);
vector<string> getIDs(Vita::string str);
inline void addNewIDsGroup();
Vita::string getRightPath(Vita::string str);
};
}
......
......@@ -20,4 +20,4 @@
#define MHWD_CONFIG_END "mhwd"
#define MHWD_USB_CONFIG_DIR "/var/lib/mhwd/usb"
#define MHWD_PCI_CONFIG_DIR "/var/lib/mhwd/pci"
#define MHWD_PCI_CONFIG_DIR "." //"/var/lib/mhwd/pci"
......@@ -16,14 +16,13 @@ using namespace std;
int main (int argc, char *argv[])
{
mhwd::hwd::printUSBDetails();
/*vector<mhwd::Device*> devices = mhwd::hwd::getPCIDevices();
vector<mhwd::Device*> devices = mhwd::hwd::getPCIDevices();
for (vector<mhwd::Device*>::const_iterator iterator = devices.begin(); iterator != devices.end(); iterator++) {
vector<mhwd::Config> configs = (*iterator)->getConfigs();
cout << (*iterator)->getClassName() << ": ";
if (!configs.empty())
cout << (*iterator)->getClassName() << ": ";
for (vector<mhwd::Config>::const_iterator iterator = configs.begin(); iterator != configs.end(); iterator++) {
mhwd::Config config = (*iterator);
......@@ -31,8 +30,9 @@ int main (int argc, char *argv[])
cout << config.getName() << " ";
}
cout << endl;
}+/
if (!configs.empty())
cout << endl;
}
/*for(unsigned int i = 0; i < devices.size(); i++) {
cout << setw(30) << devices[i]->getClassName();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment