From 3716068910b5d903f77953da11fc4a8ab06488c6 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 28 Jan 2015 15:00:19 +0100 Subject: first attempt on actually implementing programming logic. This is not finished yet. --- src/cli/Main.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'src/cli/Main.cpp') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index edcdc55..3f853b6 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -28,6 +28,7 @@ #include // Non-portable, needed for #include +#include #include #include @@ -41,16 +42,21 @@ #include #include #include +#include +#include +#include #include +#include #include const size_t ERROR_IN_COMMAND_LINE = 1; const size_t SUCCESS = 0; const size_t ERROR_UNHANDLED_EXCEPTION = 2; +using namespace ousia; + namespace po = boost::program_options; namespace fs = boost::filesystem; -namespace o = ousia; const char *MSG_COPYING = "Ousía\n" @@ -71,7 +77,7 @@ int main(int argc, char **argv) { // Initialize terminal logger. Only use color if writing to a terminal (tty) bool useColor = isatty(STDOUT_FILENO) && isatty(STDERR_FILENO); - o::TerminalLogger logger{std::cerr, useColor}; + TerminalLogger logger{std::cerr, useColor}; // Program options po::options_description desc( @@ -161,17 +167,20 @@ int main(int argc, char **argv) } // initialize global instances. - o::Manager manager; - o::Registry registry; - o::Rooted project{new o::Project(manager)}; - o::FileLocator fileLocator; + Manager manager; + Registry registry; + ResourceManager resourceManager; + ParserScope scope; + Rooted project{new Project(manager)}; + FileLocator fileLocator; + ParserContext context{registry, resourceManager, scope, project, logger}; // fill registry registry.registerDefaultExtensions(); - o::XmlParser xmlParser; + XmlParser xmlParser; registry.registerParser({"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}, - {&o::RttiTypes::Document, &o::RttiTypes::Domain, - &o::RttiTypes::Typesystem}, + {&RttiTypes::Document, &RttiTypes::Domain, + &RttiTypes::Typesystem}, &xmlParser); registry.registerResourceLocator(&fileLocator); @@ -184,11 +193,21 @@ int main(int argc, char **argv) for (auto &i : includes) { // Adding the search path as "UNKNOWN" suffices, as this search path // is automatically searched for all files. - fileLocator.addSearchPath(i, o::ResourceType::UNKNOWN); + fileLocator.addSearchPath(i, ResourceType::UNKNOWN); } } - // now all preparation is done and we can parse. TODO: But how? + // now all preparation is done and we can parse the input document. + Rooted doc = context.import(inputPath, "text/vnd.ousia.oxd", "", + {&RttiTypes::Document}); + if(logger.hasError() || doc == nullptr){ + logger.fatalError("Document could not be parsed"); + return 1; + } + // write output. + html::DemoHTMLTransformer outTransformer; + std::fstream out {outputPath}; + outTransformer.writeHTML(doc.cast(), out); return SUCCESS; } -- cgit v1.2.3