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

View File

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