From: Tomek Mrugalski Date: Tue, 6 Aug 2019 16:13:32 +0000 (+0200) Subject: Throw-away change. kea-docgen updates .json files: X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2F777-docgen-converter;p=thirdparty%2Fkea.git Throw-away change. kea-docgen updates .json files: - converts multi-line strings to list of strings. --- diff --git a/doc/docgen/kea_docgen.cc b/doc/docgen/kea_docgen.cc index 0ca6f4cc46..43f904e4ef 100644 --- a/doc/docgen/kea_docgen.cc +++ b/doc/docgen/kea_docgen.cc @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -62,8 +63,9 @@ public: sanityCheck(f, x); + writeToFile(f, x); + cmds_.insert(make_pair(cmd, x)); - cout << " looks ok." << endl; } catch (const exception& e) { cout << "ERROR: " << e.what() << endl; @@ -109,6 +111,13 @@ public: } } + void writeToFile(const string& fname, ElementPtr& x) { + string outname = fname; // + "2"; + ofstream out(outname, ios::trunc); + out << prettyPrint(x,0,4); + cout << "Content written to " << outname << endl; + } + /// @brief checks if mandatory list parameter is specified /// /// @param x a map that is being checked @@ -135,17 +144,48 @@ public: // todo: check that every element is a string } + ElementPtr stringConvertToList(ConstElementPtr& x) { + if (x->getType() != Element::string) { + return (ElementPtr()); + } + string txt = x->stringValue(); + + std::vector split; + + boost::split(split, txt, [](char c){return c == '\n';}); + + ElementPtr val = Element::createList(); + for (auto y : split) { + val->add(Element::create(y)); + } + return (val); + } + + void convertToList(ElementPtr& x, const string& name, const string& fname) { + ConstElementPtr s = x->get(name); + if (!s) { + return; + } + ElementPtr l = stringConvertToList(s); + x->set(name, l); + } + /// @brief Checks that the essential parameters for each command are defined /// /// @param fname name of the file the data was read from (printed if error is detected) /// @param x a JSON map that contains content of the file - void sanityCheck(const string& fname, const ElementPtr& x) { + void sanityCheck(const string& fname, ElementPtr& x) { requireString(x, "name", fname); requireString(x, "brief", fname); requireList (x, "support", fname); requireString(x, "avail", fname); - requireString(x, "brief", fname); + convertToList(x, "brief", fname); + convertToList(x, "cmd-syntax", fname); + convertToList(x, "cmd-comment", fname); + convertToList(x, "resp-syntax", fname); + convertToList(x, "resp-comment", fname); + // They're optional. //requireString(x, "cmd-syntax", fname); //requireString(x, "cmd-comment", fname); @@ -479,7 +519,7 @@ int main(int argc, const char*argv[]) { doc_gen.loadFiles(files); - doc_gen.generateOutput(); + //doc_gen.generateOutput(); } catch (const exception& e) { cerr << "ERROR: " << e.what() << endl; } diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index e9a00da49a..9177b2e1e0 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -1281,7 +1281,7 @@ prettyPrint(ConstElementPtr element, std::ostream& out, isc_throw(BadValue, "prettyPrint got a null pointer"); } int first_type = element->get(0)->getType(); - bool complex = false; + bool complex = true; if ((first_type == Element::list) || (first_type == Element::map)) { complex = true; }