PIConfig includes
git-svn-id: svn://db.shs.com.ru/pip@169 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
7
main.cpp
7
main.cpp
@@ -1,14 +1,17 @@
|
|||||||
#include "pikbdlistener.h"
|
#include "pikbdlistener.h"
|
||||||
#include "piconnection.h"
|
#include "piconnection.h"
|
||||||
|
#include "piconfig.h"
|
||||||
|
|
||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
PIKbdListener k;
|
/*PIKbdListener k;
|
||||||
k.enableExitCapture();
|
k.enableExitCapture();
|
||||||
PIConnection conn;
|
PIConnection conn;
|
||||||
conn.configureFromConfig("c.conf", "c");
|
conn.configureFromConfig("c.conf", "c");
|
||||||
conn.start();
|
conn.start();
|
||||||
k.start();
|
k.start();
|
||||||
WAIT_FOR_EXIT
|
WAIT_FOR_EXIT
|
||||||
return 0;
|
return 0;*/
|
||||||
|
PIConfig c("mems.conf");
|
||||||
|
piCout << c.allTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
PIConfig::~PIConfig() {
|
||||||
root.deleteBranch();
|
root.deleteBranch();
|
||||||
if (own_dev && dev) delete dev;
|
if (own_dev && dev) delete dev;
|
||||||
dev = 0;
|
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() {
|
void PIConfig::_init() {
|
||||||
|
internal = false;
|
||||||
delim = PIStringAscii(".");
|
delim = PIStringAscii(".");
|
||||||
root.delim = delim;
|
root.delim = delim;
|
||||||
empty.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() {
|
void PIConfig::parse() {
|
||||||
PIString src, str, tab, comm, all, name, type, prefix, tprefix;
|
PIString src, str, tab, comm, all, name, type, prefix, tprefix;
|
||||||
PIStringList tree;
|
PIStringList tree;
|
||||||
Entry * entry, * te, * ce;
|
Entry * entry, * te, * ce;
|
||||||
int ind, sind;
|
int ind, sind;
|
||||||
bool isNew, isPrefix;
|
bool isNew, isPrefix;
|
||||||
|
piForeach (PIConfig * c, inc_devs)
|
||||||
|
delete c;
|
||||||
|
inc_devs.clear();
|
||||||
|
includes.clear();
|
||||||
if (!isOpened()) return;
|
if (!isOpened()) return;
|
||||||
_seekToBeginDev();
|
_seekToBeginDev();
|
||||||
other.clear();
|
other.clear();
|
||||||
@@ -668,6 +728,20 @@ void PIConfig::parse() {
|
|||||||
}
|
}
|
||||||
//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") {
|
||||||
|
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();
|
name = tree.back();
|
||||||
tree.pop_back();
|
tree.pop_back();
|
||||||
entry = &root;
|
entry = &root;
|
||||||
@@ -693,7 +767,7 @@ void PIConfig::parse() {
|
|||||||
ce->delim = delim;
|
ce->delim = delim;
|
||||||
ce->_tab = tab;
|
ce->_tab = tab;
|
||||||
ce->_name = name;
|
ce->_name = name;
|
||||||
ce->_value = str.right(str.length() - ind - 1).trimmed();
|
ce->_value = entryValue(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;
|
||||||
@@ -702,6 +776,7 @@ void PIConfig::parse() {
|
|||||||
ce->_parent = entry;
|
ce->_parent = entry;
|
||||||
entry->_children << ce;
|
entry->_children << ce;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else other.back() = src;
|
} else other.back() = src;
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,6 +466,7 @@ public:
|
|||||||
void setDelimiter(const PIString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
void setDelimiter(const PIString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PIConfig(const PIString & path, PIStringList dirs);
|
||||||
void _init();
|
void _init();
|
||||||
void _clearDev();
|
void _clearDev();
|
||||||
void _flushDev();
|
void _flushDev();
|
||||||
@@ -482,12 +483,17 @@ private:
|
|||||||
void removeEntry(Branch & b, Entry * e);
|
void removeEntry(Branch & b, Entry * e);
|
||||||
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();
|
||||||
|
PIString entryValue(PIString v);
|
||||||
void parse();
|
void parse();
|
||||||
|
|
||||||
int centry;
|
int centry;
|
||||||
bool own_dev;
|
bool own_dev, internal;
|
||||||
|
PIVector<PIConfig * > includes, inc_devs;
|
||||||
|
Branch all_includes;
|
||||||
PIIODevice * dev;
|
PIIODevice * dev;
|
||||||
PIString delim;
|
PIString delim;
|
||||||
|
PIStringList incdirs;
|
||||||
Entry root, empty;
|
Entry root, empty;
|
||||||
uint lines;
|
uint lines;
|
||||||
PIStringList other;
|
PIStringList other;
|
||||||
|
|||||||
Reference in New Issue
Block a user