From ad45bc892752571fec46b21564e4683c074f1d46 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Thu, 22 Sep 2011 01:43:38 +0200 Subject: [PATCH] Tweak C++0x API a bit, to prepare for include. Also, output to stdout instead of ugly temporary files. --- c++0x/attribute-empty.cpp | 3 ++- c++0x/attribute.cpp | 3 ++- c++0x/attribute2.cpp | 3 ++- c++0x/attribute3.cpp | 3 ++- c++0x/clone.cpp | 3 ++- c++0x/namespace.cpp | 3 ++- c++0x/namespace2.cpp | 3 ++- c++0x/passthru.cpp | 3 ++- c++0x/simple.cpp | 3 ++- c++0x/structure.cpp | 3 ++- c++0x/xml-template.cpp | 16 ++++++++++------ c++0x/xml-template.h | 7 ++++--- tests/test.sh | 2 +- 13 files changed, 35 insertions(+), 20 deletions(-) diff --git a/c++0x/attribute-empty.cpp b/c++0x/attribute-empty.cpp index b79836b..96c587d 100644 --- a/c++0x/attribute-empty.cpp +++ b/c++0x/attribute-empty.cpp @@ -11,6 +11,7 @@ int main(int argc, char **argv) make_pair("#things", new Clone { }), }; - process_file("../xml/clone.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/clone.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/attribute.cpp b/c++0x/attribute.cpp index 6c341bd..e651323 100644 --- a/c++0x/attribute.cpp +++ b/c++0x/attribute.cpp @@ -28,6 +28,7 @@ int main(int argc, char **argv) }), }; - process_file("../xml/clone.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/clone.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/attribute2.cpp b/c++0x/attribute2.cpp index 94cf17d..478dd51 100644 --- a/c++0x/attribute2.cpp +++ b/c++0x/attribute2.cpp @@ -16,6 +16,7 @@ int main(int argc, char **argv) }, { "odd", "even" } }), }; - process_file("../xml/clone.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/clone.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/attribute3.cpp b/c++0x/attribute3.cpp index a3f8b6e..d2746e8 100644 --- a/c++0x/attribute3.cpp +++ b/c++0x/attribute3.cpp @@ -17,6 +17,7 @@ int main(int argc, char **argv) }, { "odd", "even" } }), }; - process_file("../xml/clone.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/clone.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/clone.cpp b/c++0x/clone.cpp index 81b6d11..6911a7d 100644 --- a/c++0x/clone.cpp +++ b/c++0x/clone.cpp @@ -16,6 +16,7 @@ int main(int argc, char **argv) }), }; - process_file("../xml/clone.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/clone.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/namespace.cpp b/c++0x/namespace.cpp index 7298576..3399957 100644 --- a/c++0x/namespace.cpp +++ b/c++0x/namespace.cpp @@ -14,6 +14,7 @@ int main(int argc, char **argv) make_pair("#moretest", new Replace("bar")), }; - process_file("../xml/namespace.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/namespace.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/namespace2.cpp b/c++0x/namespace2.cpp index 2b438d3..060eb0e 100644 --- a/c++0x/namespace2.cpp +++ b/c++0x/namespace2.cpp @@ -11,6 +11,7 @@ int main(int argc, char **argv) make_pair("#hello", new Replace("Replaced.")), }; - process_file("../xml/namespace2.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/namespace2.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/passthru.cpp b/c++0x/passthru.cpp index f4fc636..28cc2f4 100644 --- a/c++0x/passthru.cpp +++ b/c++0x/passthru.cpp @@ -9,6 +9,7 @@ using namespace std; int main(int argc, char **argv) { Substitute master_directive = {}; - process_file("../xml/passthru.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/passthru.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/simple.cpp b/c++0x/simple.cpp index 5ac223d..0c89542 100644 --- a/c++0x/simple.cpp +++ b/c++0x/simple.cpp @@ -11,6 +11,7 @@ int main(int argc, char **argv) make_pair("#hello", new Replace("Hello world!")), }; - process_file("../xml/simple.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/simple.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/structure.cpp b/c++0x/structure.cpp index 2447feb..facaade 100644 --- a/c++0x/structure.cpp +++ b/c++0x/structure.cpp @@ -14,6 +14,7 @@ int main(int argc, char **argv) }), }; - process_file("../xml/structure.xml", argv[1], &master_directive); + xmlDocPtr doc = process_file("../xml/structure.xml", &master_directive); + output_to_fd_and_free(doc, 1); return(0); } diff --git a/c++0x/xml-template.cpp b/c++0x/xml-template.cpp index 30e5a7e..e8fc0ed 100644 --- a/c++0x/xml-template.cpp +++ b/c++0x/xml-template.cpp @@ -196,17 +196,21 @@ void Substitute::process(xmlNode *node, bool clean) } } -void process_file(const string &input_filename, - const string &output_filename, - Directive *root_directive) +xmlDocPtr process_file(const string &input_filename, + Directive *root_directive) { LIBXML_TEST_VERSION xmlDocPtr doc = xmlParseFile(input_filename.c_str()); root_directive->process(xmlDocGetRootElement(doc), true); - xmlSaveFile(output_filename.c_str(), doc); - xmlFreeDoc(doc); - xmlCleanupParser(); xmlMemoryDump(); + return doc; +} + +void output_to_fd_and_free(xmlDocPtr doc, int fd) +{ + xmlOutputBufferPtr buf = xmlOutputBufferCreateFd(fd, NULL); + xmlSaveFileTo(buf, doc, NULL); + xmlFreeDoc(doc); } diff --git a/c++0x/xml-template.h b/c++0x/xml-template.h index d29cbae..3567186 100644 --- a/c++0x/xml-template.h +++ b/c++0x/xml-template.h @@ -59,8 +59,9 @@ class Alternate : public Clone { const std::vector &alternatives); }; -void process_file(const std::string &input_filename, - const std::string &output_filename, - Directive *root_directive); +xmlDocPtr process_file(const std::string &input_filename, + Directive *root_directive); + +void output_to_fd_and_free(xmlDocPtr doc, int fd); #endif // !defined(_XML_TEMPLATE_H) diff --git a/tests/test.sh b/tests/test.sh index 43ccadc..600f095 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -31,7 +31,7 @@ for L in $LANGUAGES; do ruby -I../ruby ../ruby/$T.rb > $TEMPFILE fi if [ "$L" = "c++0x" ]; then - ( cd ../c++0x && make -s $T ) && ../c++0x/$T $TEMPFILE + ( cd ../c++0x && make -s $T ) && ../c++0x/$T > $TEMPFILE fi perl ./xml-diff.pl $TEMPFILE reference/$T.xml -- 2.39.2