summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-27 21:19:49 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-27 21:19:49 +0100
commit048db07ca91505ccfcb98e29ed6868f1aa64a514 (patch)
tree0b361a25bcce174fd2332a52abe228e037519c0d
parent7a959de0b1bf890c5deefdc132fe30f20661ca9b (diff)
wrote initialization section for program logic, which is probably not complete yet. also improved output path handling.
-rw-r--r--src/cli/Main.cpp68
1 files changed, 53 insertions, 15 deletions
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 <boost/program_options.hpp>
+#include <core/Registry.hpp>
+#include <core/common/Rtti.hpp>
+#include <core/frontend/TerminalLogger.hpp>
+#include <core/managed/Manager.hpp>
+#include <core/model/Document.hpp>
+#include <core/model/Domain.hpp>
+#include <core/model/Project.hpp>
+#include <core/model/Typesystem.hpp>
+#include <plugins/filesystem/FileLocator.hpp>
+#include <plugins/xml/XmlParser.hpp>
+
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::string>() << std::endl;
- std::cout << "output : " << outputPath << std::endl;
- std::cout << "format : " << vm["format"].as<std::string>() << std::endl;
- if(vm.count("include")){
- std::vector<std::string> includes = vm["include"].as<std::vector<std::string>>();
- 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<o::Project> 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<std::string> includes =
+ vm["include"].as<std::vector<std::string>>();
+ 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;
}