PIConfig multiline support
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(pip)
|
project(pip)
|
||||||
set(_PIP_MAJOR 1)
|
set(_PIP_MAJOR 1)
|
||||||
set(_PIP_MINOR 15)
|
set(_PIP_MINOR 15)
|
||||||
set(_PIP_REVISION 0)
|
set(_PIP_REVISION 1)
|
||||||
set(_PIP_SUFFIX alpha)
|
set(_PIP_SUFFIX alpha)
|
||||||
set(_PIP_COMPANY SHS)
|
set(_PIP_COMPANY SHS)
|
||||||
set(_PIP_DOMAIN org.SHS)
|
set(_PIP_DOMAIN org.SHS)
|
||||||
|
|||||||
20
main.cpp
20
main.cpp
@@ -114,29 +114,13 @@ private:
|
|||||||
|
|
||||||
PIKbdListener kbd;
|
PIKbdListener kbd;
|
||||||
|
|
||||||
#include "pigpio.h"
|
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
int pin = PIString(argv[1]).toInt();
|
|
||||||
PIGPIO::instance()->initPin(pin, PIGPIO::In);
|
|
||||||
PIGPIO::instance()->pinBeginWatch(pin);
|
|
||||||
PIGPIO::instance()->start();
|
|
||||||
CONNECTL(PIGPIO::instance(), pinChanged, [](int pin, bool value){
|
|
||||||
piCout << "pin" << pin << "->" << value;}
|
|
||||||
);
|
|
||||||
kbd.enableExitCapture();
|
|
||||||
kbd.start();
|
|
||||||
bool val = false;
|
|
||||||
while (!PIKbdListener::exiting) {
|
|
||||||
piMSleep(500);
|
|
||||||
/*PIGPIO::instance()->pinSet(4, val);
|
|
||||||
piCout << PIGPIO::instance()->pinState(4);
|
|
||||||
val = !val;*/
|
|
||||||
}
|
|
||||||
/*PIStringList dl = PISerial::availableDevices();
|
/*PIStringList dl = PISerial::availableDevices();
|
||||||
piCout << dl;
|
piCout << dl;
|
||||||
PISerial ser(dl[0]);
|
PISerial ser(dl[0]);
|
||||||
piCout << ser.open(PIIODevice::ReadWrite) << &ser;
|
piCout << ser.open(PIIODevice::ReadWrite) << &ser;
|
||||||
*/
|
*/
|
||||||
|
PIConfig conf("d:/orders/nicirt/bin/spec_core.conf", PIIODevice::ReadOnly);
|
||||||
|
piCout << conf.allTree();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
|||||||
|
|
||||||
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
||||||
PIString nl = p + " ";
|
PIString nl = p + " ";
|
||||||
if (!_value.isEmpty()) s << p << _name << " = " << _value << PICoutManipulators::NewLine;
|
if (!_value.isEmpty()) s << p << _name << " = " << _value << " (" << _type << " " << _comment << ")" << PICoutManipulators::NewLine;
|
||||||
else std::cout << p << _name << std::endl;
|
else std::cout << p << _name << std::endl;
|
||||||
piForeachC (Entry * i, _children) i->piCoutt(s, nl);
|
piForeachC (Entry * i, _children) i->piCoutt(s, nl);
|
||||||
}
|
}
|
||||||
@@ -261,6 +261,7 @@ PIConfig::PIConfig(const PIString & path, PIIODevice::DeviceMode mode) {
|
|||||||
dev = new PIFile(path, mode);
|
dev = new PIFile(path, mode);
|
||||||
if (!dev->isOpened())
|
if (!dev->isOpened())
|
||||||
dev->open(path, mode);
|
dev->open(path, mode);
|
||||||
|
incdirs << PIFile::fileInfo(path).dir();
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +278,11 @@ PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) {
|
|||||||
_init();
|
_init();
|
||||||
own_dev = false;
|
own_dev = false;
|
||||||
dev = device;
|
dev = device;
|
||||||
if (dev) dev->open(mode);
|
if (dev) {
|
||||||
|
dev->open(mode);
|
||||||
|
if (PIString(dev->className()) == "PIFile")
|
||||||
|
incdirs << PIFile::fileInfo(((PIFile*)dev)->path()).dir();
|
||||||
|
}
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,9 +721,9 @@ void PIConfig::parse() {
|
|||||||
//piCout << "[PIConfig] charset" << PIFile::defaultCharset();
|
//piCout << "[PIConfig] charset" << PIFile::defaultCharset();
|
||||||
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 = 0, * te = 0, * ce = 0;
|
||||||
int ind, sind;
|
int ind, sind;
|
||||||
bool isNew, isPrefix;
|
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
|
||||||
piForeach (PIConfig * c, inc_devs)
|
piForeach (PIConfig * c, inc_devs)
|
||||||
delete c;
|
delete c;
|
||||||
inc_devs.clear();
|
inc_devs.clear();
|
||||||
@@ -739,27 +744,44 @@ void PIConfig::parse() {
|
|||||||
//piCout << "line \"" << str << "\"";
|
//piCout << "line \"" << str << "\"";
|
||||||
tab = str.left(str.find(str.trimmed().left(1)));
|
tab = str.left(str.find(str.trimmed().left(1)));
|
||||||
str.trim();
|
str.trim();
|
||||||
//cout << endl << str << endl << endl;
|
|
||||||
// piCout << "[PIConfig] str" << str.size() << str << str.toUTF8();
|
|
||||||
all = str;
|
all = str;
|
||||||
|
|
||||||
|
sind = str.find('#');
|
||||||
|
if (sind > 0) {
|
||||||
|
comm = str.mid(sind + 1).trimmed();
|
||||||
|
if (!comm.isEmpty()) {
|
||||||
|
type = comm[0];
|
||||||
|
comm.cutLeft(1).trim();
|
||||||
|
} else type = "s";
|
||||||
|
str = str.left(sind).trim();
|
||||||
|
} else {
|
||||||
|
type = "s";
|
||||||
|
comm = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.endsWith("\\")) {
|
||||||
|
isMultiline = true;
|
||||||
|
str.cutRight(1).trim();
|
||||||
|
} else
|
||||||
|
isMultiline = false;
|
||||||
|
|
||||||
|
if (wasMultiline) {
|
||||||
|
wasMultiline = false;
|
||||||
|
if (ce) {
|
||||||
|
ce->_value += str;
|
||||||
|
ce->_all += "\\\n" + all;
|
||||||
|
}
|
||||||
|
str.clear();
|
||||||
|
}
|
||||||
|
wasMultiline = isMultiline;
|
||||||
|
|
||||||
|
//piCout << "[PIConfig] str" << str.size() << str << str.toUTF8();
|
||||||
ind = str.find('=');
|
ind = str.find('=');
|
||||||
if ((ind > 0) && (str[0] != '#')) {
|
if ((ind > 0) && (str[0] != '#')) {
|
||||||
sind = str.find('#');
|
|
||||||
if (sind > 0) {
|
|
||||||
comm = str.right(str.length() - sind - 1).trimmed();
|
|
||||||
if (comm.length() > 0) type = comm[0];
|
|
||||||
else type = "s";
|
|
||||||
comm = comm.right(comm.length() - 1).trimmed();
|
|
||||||
str = str.left(sind);
|
|
||||||
} else {
|
|
||||||
type = "s";
|
|
||||||
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") {
|
||||||
name = str.right(str.length() - ind - 1).trimmed();
|
name = str.mid(ind + 1).trimmed();
|
||||||
PIConfig * iconf = new PIConfig(name, incdirs);
|
PIConfig * iconf = new PIConfig(name, incdirs);
|
||||||
//piCout << "include" << name << iconf->dev;
|
//piCout << "include" << name << iconf->dev;
|
||||||
if (!iconf->dev) {
|
if (!iconf->dev) {
|
||||||
@@ -797,7 +819,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 = str.mid(ind + 1).trimmed();
|
||||||
ce->_type = type;
|
ce->_type = type;
|
||||||
ce->_comment = comm;
|
ce->_comment = comm;
|
||||||
//piCout << "[PIConfig] comm" << comm.size() << comm << comm.toUTF8();
|
//piCout << "[PIConfig] comm" << comm.size() << comm << comm.toUTF8();
|
||||||
|
|||||||
@@ -512,7 +512,10 @@ std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}
|
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {
|
||||||
|
s << v.value() << "(" << v.type() << v.comment() << ")";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \relatesalso PIConfig \relatesalso PIIODevice
|
/** \relatesalso PIConfig \relatesalso PIIODevice
|
||||||
|
|||||||
Reference in New Issue
Block a user