From 21f8a035d8ca050bd535a2fdc00058a9be2679f9 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Sat, 23 May 2020 21:41:47 +0300 Subject: [PATCH] PIConfig multiline support --- CMakeLists.txt | 2 +- main.cpp | 20 ++--------- src_main/io_devices/piconfig.cpp | 62 +++++++++++++++++++++----------- src_main/io_devices/piconfig.h | 5 ++- 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bccf8a1c..1e675e46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(_PIP_MAJOR 1) set(_PIP_MINOR 15) -set(_PIP_REVISION 0) +set(_PIP_REVISION 1) set(_PIP_SUFFIX alpha) set(_PIP_COMPANY SHS) set(_PIP_DOMAIN org.SHS) diff --git a/main.cpp b/main.cpp index d1e9e2f2..ed0d1135 100644 --- a/main.cpp +++ b/main.cpp @@ -114,29 +114,13 @@ private: PIKbdListener kbd; -#include "pigpio.h" - 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(); piCout << dl; PISerial ser(dl[0]); piCout << ser.open(PIIODevice::ReadWrite) << &ser; */ + PIConfig conf("d:/orders/nicirt/bin/spec_core.conf", PIIODevice::ReadOnly); + piCout << conf.allTree(); return 0; } diff --git a/src_main/io_devices/piconfig.cpp b/src_main/io_devices/piconfig.cpp index 70b7b28d..edd71692 100755 --- a/src_main/io_devices/piconfig.cpp +++ b/src_main/io_devices/piconfig.cpp @@ -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 { 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; 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); if (!dev->isOpened()) dev->open(path, mode); + incdirs << PIFile::fileInfo(path).dir(); parse(); } @@ -277,7 +278,11 @@ PIConfig::PIConfig(PIIODevice * device, PIIODevice::DeviceMode mode) { _init(); own_dev = false; 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(); } @@ -716,9 +721,9 @@ void PIConfig::parse() { //piCout << "[PIConfig] charset" << PIFile::defaultCharset(); PIString src, str, tab, comm, all, name, type, prefix, tprefix; PIStringList tree; - Entry * entry, * te, * ce; + Entry * entry = 0, * te = 0, * ce = 0; int ind, sind; - bool isNew, isPrefix; + bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false; piForeach (PIConfig * c, inc_devs) delete c; inc_devs.clear(); @@ -739,27 +744,44 @@ void PIConfig::parse() { //piCout << "line \"" << str << "\""; tab = str.left(str.find(str.trimmed().left(1))); str.trim(); - //cout << endl << str << endl << endl; -// piCout << "[PIConfig] str" << str.size() << str << str.toUTF8(); 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('='); 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(); tree = (prefix + str.left(ind).trimmed()).split(delim); if (tree.front() == "include") { - name = str.right(str.length() - ind - 1).trimmed(); + name = str.mid(ind + 1).trimmed(); PIConfig * iconf = new PIConfig(name, incdirs); //piCout << "include" << name << iconf->dev; if (!iconf->dev) { @@ -797,7 +819,7 @@ void PIConfig::parse() { ce->delim = delim; ce->_tab = tab; ce->_name = name; - ce->_value = str.right(str.length() - ind - 1).trimmed(); + ce->_value = str.mid(ind + 1).trimmed(); ce->_type = type; ce->_comment = comm; //piCout << "[PIConfig] comm" << comm.size() << comm << comm.toUTF8(); diff --git a/src_main/io_devices/piconfig.h b/src_main/io_devices/piconfig.h index edde0769..aeba3861 100755 --- a/src_main/io_devices/piconfig.h +++ b/src_main/io_devices/piconfig.h @@ -512,7 +512,10 @@ std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v); #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::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