From 048db07ca91505ccfcb98e29ed6868f1aa64a514 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 27 Jan 2015 21:19:49 +0100 Subject: wrote initialization section for program logic, which is probably not complete yet. also improved output path handling. --- src/cli/Main.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 15 deletions(-) (limited to 'src/cli') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 73c46ba..24c0ec7 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -29,11 +29,23 @@ #include +#include +#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; namespace po = boost::program_options; +namespace o = ousia; int main(int argc, char **argv) { @@ -83,28 +95,54 @@ int main(int argc, char **argv) std::cerr << desc << std::endl; return ERROR_IN_COMMAND_LINE; } - - if(!vm.count("output")){ - // TODO: Handle this better. + + // prepare output path + if (!vm.count("output")) { outputPath = inputPath; - if(outputPath.find(".oxd") != std::string::npos){ - outputPath.erase(outputPath.end()-3, outputPath.end()); + auto pos = outputPath.find_last_of('.'); + if (pos != std::string::npos) { + outputPath.erase(outputPath.begin() + pos + 1, outputPath.end()); outputPath += format; + std::cout << "Using " << outputPath << " as output path." + << std::endl; } } - // TODO: Program logic. - std::cout << "input : " << vm["input"].as() << std::endl; - std::cout << "output : " << outputPath << std::endl; - std::cout << "format : " << vm["format"].as() << std::endl; - if(vm.count("include")){ - std::vector includes = vm["include"].as>(); - std::cout << "includes : "; - for(auto& i : includes){ - std::cout << i << ", "; + // initialize global instances. + o::TerminalLogger logger{std::cerr, true}; + o::Manager manager; + o::Registry registry; + o::Rooted project{new o::Project(manager)}; + o::FileLocator fileLocator; + + // fill registry + registry.registerDefaultExtensions(); + o::XmlParser xmlParser; + registry.registerParser( + {"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}, + // TODO: Why don't we have domains here? + {&o::RttiTypes::Document, &o::RttiTypes::Typesystem}, &xmlParser); + registry.registerResourceLocator(&fileLocator); + + // register search paths + fileLocator.addDefaultSearchPaths(); + // in user includes we allow every kind of resource. + if (vm.count("include")) { + std::vector includes = + vm["include"].as>(); + for (auto &i : includes) { + fileLocator.addSearchPath(i, o::ResourceType::UNKNOWN); + fileLocator.addSearchPath(i, o::ResourceType::DOMAIN_DESC); + fileLocator.addSearchPath(i, o::ResourceType::TYPESYSTEM); + fileLocator.addSearchPath(i, o::ResourceType::DOCUMENT); + fileLocator.addSearchPath(i, o::ResourceType::ATTRIBUTES); + fileLocator.addSearchPath(i, o::ResourceType::STYLESHEET); + fileLocator.addSearchPath(i, o::ResourceType::SCRIPT); + fileLocator.addSearchPath(i, o::ResourceType::DATA); } - std::cout << std::endl; } + // now all preparation is done and we can parse. TODO: But how? + return SUCCESS; } -- cgit v1.2.3