From b8a7fdfb23b5b49e428e02cc8c87e4e429d22633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 28 Jan 2016 08:25:49 +0000 Subject: [PATCH] PIConfig includes improvements git-svn-id: svn://db.shs.com.ru/pip@172 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- main.cpp | 3 ++- src/io/piconfig.cpp | 24 ++++++++++++++++-------- src/io/piconfig.h | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 03cf35ee..03048ba7 100644 --- a/main.cpp +++ b/main.cpp @@ -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(); } diff --git a/src/io/piconfig.cpp b/src/io/piconfig.cpp index 43386862..f225fd37 100755 --- a/src/io/piconfig.cpp +++ b/src/io/piconfig.cpp @@ -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; diff --git a/src/io/piconfig.h b/src/io/piconfig.h index fd8f88ad..0b8ada9b 100755 --- a/src/io/piconfig.h +++ b/src/io/piconfig.h @@ -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;