franta-hg@28: /** franta-hg@28: * parameter-lister franta-hg@28: * Copyright © 2015 František Kučera (frantovo.cz) franta-hg@28: * franta-hg@28: * This program is free software: you can redistribute it and/or modify franta-hg@28: * it under the terms of the GNU General Public License as published by franta-hg@28: * the Free Software Foundation, either version 3 of the License, or franta-hg@28: * (at your option) any later version. franta-hg@28: * franta-hg@28: * This program is distributed in the hope that it will be useful, franta-hg@28: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@28: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@28: * GNU General Public License for more details. franta-hg@28: * franta-hg@28: * You should have received a copy of the GNU General Public License franta-hg@28: * along with this program. If not, see . franta-hg@28: */ franta-hg@0: #include franta-hg@1: #include franta-hg@3: #include franta-hg@16: #include franta-hg@3: #include franta-hg@5: #include franta-hg@10: #include franta-hg@3: franta-hg@7: #include "info/globalcode/parameterLister/OutputModule.h" franta-hg@7: #include "info/globalcode/parameterLister/TerminalOutputModule.h" franta-hg@0: franta-hg@0: using namespace std; franta-hg@3: using namespace info::globalcode::parameterLister; franta-hg@0: franta-hg@5: namespace info { franta-hg@5: namespace globalcode { franta-hg@5: namespace parameterLister { franta-hg@5: franta-hg@16: const string ENV_BASE = "PARAMETER_LISTER"; franta-hg@16: const string ENV_OUTPUT_MODULE_NAME = ENV_BASE + "_OUTPUT"; franta-hg@16: franta-hg@5: boost::optional getenv(const string name) { franta-hg@5: const char * value = ::getenv(name.c_str()); franta-hg@5: if (value == 0) { franta-hg@5: return boost::optional(); franta-hg@5: } else { franta-hg@5: return boost::optional(value); franta-hg@5: } franta-hg@5: } franta-hg@5: franta-hg@5: } franta-hg@5: } franta-hg@5: } franta-hg@5: franta-hg@16: shared_ptr chooseOutputModule() { franta-hg@16: boost::optional moduleName = getenv(ENV_OUTPUT_MODULE_NAME); franta-hg@16: if (moduleName.is_initialized()) { franta-hg@16: // TODO: use a map instead of sequence of IFs franta-hg@16: if (moduleName.get() == "terminal") { franta-hg@16: return shared_ptr(new TerminalOutputModule()); franta-hg@16: } franta-hg@16: } franta-hg@16: franta-hg@16: return shared_ptr(new OutputModule()); franta-hg@16: } franta-hg@16: franta-hg@3: int main(int argc, char* argv[]) { franta-hg@4: franta-hg@16: /** Load arguments */ franta-hg@3: string command = argv[0]; franta-hg@3: vector args; franta-hg@3: franta-hg@3: for (int i = 1; i < argc; i++) { franta-hg@3: args.push_back(argv[i]); franta-hg@3: } franta-hg@3: franta-hg@16: /** Do formatting */ franta-hg@16: shared_ptr outputModule = chooseOutputModule(); franta-hg@4: franta-hg@16: return outputModule->process(cout, command, args); franta-hg@10: }