PIConfig includes improvements

git-svn-id: svn://db.shs.com.ru/pip@172 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2016-01-28 08:25:49 +00:00
parent 0966a6088c
commit b8a7fdfb23
3 changed files with 19 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ int main (int argc, char * argv[]) {
k.start();
WAIT_FOR_EXIT
return 0;*/
piCout << PIEthernet::resolve(argv[1]);
PIConfig c("mems.conf", PIIODevice::ReadOnly);
piCout << c.allTree();
}

View File

@@ -666,19 +666,26 @@ void PIConfig::updateIncludes() {
}
PIString PIConfig::entryValue(PIString v) {
PIString PIConfig::parseLine(PIString v) {
int i = -1, l = 0;
while (1) {
i = v.find("${");
if (i < 0) break;
PIString w = v.mid(i + 1).takeRange('{', '}'), r;
l = w.length() + 3;
w = parseLine(w);
w.trim();
piForeachC (PIConfig::Entry * e, all_includes)
if (e->_full_name == w) {
r = e->_value;
break;
}
bool ex = false;
PIConfig::Entry & me = getValue(w, "", &ex);
if (ex) {
r = me._value;
} else {
piForeachC (PIConfig::Entry * e, all_includes)
if (e->_full_name == w) {
r = e->_value;
break;
}
}
v.replace(i, l, r);
}
return v;
@@ -701,7 +708,7 @@ void PIConfig::parse() {
lines = centry = 0;
while (!_isEndDev()) {
other.push_back(PIString());
src = str = _readLineDev();
src = str = parseLine(_readLineDev());
tprefix = getPrefixFromLine(src, &isPrefix);
if (isPrefix) {
prefix = tprefix;
@@ -726,6 +733,7 @@ void PIConfig::parse() {
type = "s";
comm = "";
}
//name = str.left(ind).trimmed();
tree = (prefix + str.left(ind).trimmed()).split(delim);
if (tree.front() == "include") {
@@ -767,7 +775,7 @@ void PIConfig::parse() {
ce->delim = delim;
ce->_tab = tab;
ce->_name = name;
ce->_value = entryValue(str.right(str.length() - ind - 1).trimmed());
ce->_value = str.right(str.length() - ind - 1).trimmed();
ce->_type = type;
ce->_comment = comm;
ce->_line = lines;

View File

@@ -484,7 +484,7 @@ private:
void deleteEntry(Entry * e) {piForeach (Entry * i, e->_children) deleteEntry(i); delete e;}
PIString getPrefixFromLine(PIString line, bool * exists);
void updateIncludes();
PIString entryValue(PIString v);
PIString parseLine(PIString v);
void parse();
int centry;