From 11f24ffe8aae1deecffd44267d25f518f3d9bbe3 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 28 Jan 2015 01:45:26 +0100 Subject: Added my Senf to Main.cpp --- src/cli/Main.cpp | 61 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 05d89ca..edcdc55 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -24,9 +24,13 @@ * * @author Benjamin Paaßen (bpaassen@techfak.uni-bielefeld.de) */ + +#include // Non-portable, needed for + #include #include +#include #include #include @@ -45,13 +49,34 @@ const size_t SUCCESS = 0; const size_t ERROR_UNHANDLED_EXCEPTION = 2; namespace po = boost::program_options; +namespace fs = boost::filesystem; namespace o = ousia; +const char *MSG_COPYING = + "Ousía\n" + "Semantic Document Markup\n" + "Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel\n" + "\n" + "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n"; + 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}; + // Program options po::options_description desc( - "Program usage\n./ousia [optional options] <-F format> \nProgram options"); + "Program usage\n./ousia [optional options] <-F format> \nProgram options"); std::string inputPath; std::string outputPath; std::string format; @@ -87,11 +112,9 @@ int main(int argc, char **argv) // first check the help option. if (vm.count("help")) { - std::cout - << "Ousia" << std::endl - << "Copyright (C) 2014 Benjamin Paassen, Andreas Stoeckel" - // write the program options description as generated by boost - << std::endl << desc << std::endl << std::endl; + // write the program options description as generated by boost + std::cout << MSG_COPYING << std::endl << std::endl << desc + << std::endl << std::endl; return SUCCESS; } @@ -100,11 +123,17 @@ int main(int argc, char **argv) po::notify(vm); } catch (po::error &e) { - std::cerr << "ERROR: " << e.what() << std::endl << std::endl; + logger.error(e.what()); std::cerr << desc << std::endl; return ERROR_IN_COMMAND_LINE; } + // To comply with standard UNIX conventions the following should be changed: + // TODO: Always write to the working directory (not to the input directory!) + // TODO: Allow "-" for input and output files for reading from stdin and + // writing to stdout + // TODO: Best use boost::filesystem for path operations + // prepare output path if (!vm.count("output")) { outputPath = inputPath; @@ -132,7 +161,6 @@ int main(int argc, char **argv) } // initialize global instances. - o::TerminalLogger logger{std::cerr, true}; o::Manager manager; o::Registry registry; o::Rooted project{new o::Project(manager)}; @@ -141,10 +169,10 @@ int main(int argc, char **argv) // 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.registerParser({"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}, + {&o::RttiTypes::Document, &o::RttiTypes::Domain, + &o::RttiTypes::Typesystem}, + &xmlParser); registry.registerResourceLocator(&fileLocator); // register search paths @@ -154,14 +182,9 @@ int main(int argc, char **argv) std::vector includes = vm["include"].as>(); 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, 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); } } -- cgit v1.2.3