PIConfig includes

git-svn-id: svn://db.shs.com.ru/pip@169 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2016-01-18 11:34:15 +00:00
parent e6976eda0c
commit 18bb64bf40
3 changed files with 117 additions and 33 deletions

View File

@@ -262,10 +262,38 @@ PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) {
}
PIConfig::PIConfig(const PIString & path, PIStringList dirs) {
_init();
internal = true;
own_dev = true;
dev = new PIFile(path, PIIODevice::ReadOnly);
incdirs = dirs;
incdirs << PIFile::fileInfo(path).dir();
while (!dev->isOpened()) {
if (dirs.isEmpty()) break;
PIString cp = dirs.back();
if (cp.endsWith("/") || cp.endsWith("\\")) cp.pop_back();
cp += "/" + path;
dev->open(cp, PIIODevice::ReadOnly);
dirs.pop_back();
}
if (!dev->isOpened()) {
delete dev;
dev = 0;
return;
}
parse();
}
PIConfig::~PIConfig() {
root.deleteBranch();
if (own_dev && dev) delete dev;
dev = 0;
piForeach (PIConfig * c, inc_devs)
delete c;
inc_devs.clear();
includes.clear();
}
@@ -290,6 +318,7 @@ bool PIConfig::open(PIString * string, PIIODevice::DeviceMode mode) {
void PIConfig::_init() {
internal = false;
delim = PIStringAscii(".");
root.delim = delim;
empty.delim = delim;
@@ -629,12 +658,43 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
}
void PIConfig::updateIncludes() {
if (internal) return;
all_includes.clear();
piForeach (PIConfig * c, includes)
all_includes << c->allLeaves();
}
PIString PIConfig::entryValue(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.trim();
piForeachC (PIConfig::Entry * e, all_includes)
if (e->_full_name == w) {
r = e->_value;
break;
}
v.replace(i, l, r);
}
return v;
}
void PIConfig::parse() {
PIString src, str, tab, comm, all, name, type, prefix, tprefix;
PIStringList tree;
Entry * entry, * te, * ce;
int ind, sind;
bool isNew, isPrefix;
piForeach (PIConfig * c, inc_devs)
delete c;
inc_devs.clear();
includes.clear();
if (!isOpened()) return;
_seekToBeginDev();
other.clear();
@@ -668,39 +728,54 @@ void PIConfig::parse() {
}
//name = str.left(ind).trimmed();
tree = (prefix + str.left(ind).trimmed()).split(delim);
name = tree.back();
tree.pop_back();
entry = &root;
piForeachC (PIString & i, tree) {
te = entry->findChild(i);
if (te == 0) {
if (tree.front() == "include") {
name = str.right(str.length() - ind - 1).trimmed();
PIConfig * iconf = new PIConfig(name, incdirs);
//piCout << "include" << name << iconf->dev;
if (!iconf->dev) {
delete iconf;
} else {
inc_devs << iconf;
includes << iconf << iconf->includes;
updateIncludes();
}
//piCout << "includes" << includes;
other.back() = src;
} else {
name = tree.back();
tree.pop_back();
entry = &root;
piForeachC (PIString & i, tree) {
te = entry->findChild(i);
if (te == 0) {
ce = new Entry();
ce->delim = delim;
ce->_tab = tab;
ce->_line = lines;
ce->_name = i;
ce->_parent = entry;
entry->_children << ce;
entry = ce;
} else entry = te;
}
isNew = false;
ce = entry->findChild(name);
if (ce == 0) {
ce = new Entry();
ce->delim = delim;
ce->_tab = tab;
ce->_line = lines;
ce->_name = i;
isNew = true;
}
ce->delim = delim;
ce->_tab = tab;
ce->_name = name;
ce->_value = entryValue(str.right(str.length() - ind - 1).trimmed());
ce->_type = type;
ce->_comment = comm;
ce->_line = lines;
ce->_all = all;
if (isNew) {
ce->_parent = entry;
entry->_children << ce;
entry = ce;
} else entry = te;
}
isNew = false;
ce = entry->findChild(name);
if (ce == 0) {
ce = new Entry();
isNew = true;
}
ce->delim = delim;
ce->_tab = tab;
ce->_name = name;
ce->_value = str.right(str.length() - ind - 1).trimmed();
ce->_type = type;
ce->_comment = comm;
ce->_line = lines;
ce->_all = all;
if (isNew) {
ce->_parent = entry;
entry->_children << ce;
}
}
} else other.back() = src;
lines++;