31 #ifdef OW_BOOST_PROGRAM_OPTIONS_FIX
35 namespace program_options
41 #include <boost/program_options.hpp>
42 #include <boost/filesystem.hpp>
44 #include "core/common/WLogger.h"
45 #include "core/common/WIOTools.h"
46 #include "core/common/WLogStream.h"
47 #include "core/common/WThreadedRunner.h"
48 #include "core/common/WSegmentationFault.h"
49 #include "core/common/WPathHelper.h"
51 #include "core/kernel/WKernel.h"
52 #include "core/kernel/WModuleFactory.h"
54 #include "WScriptUI.h"
56 #include "core/WVersion.h"
63 std::cout <<
"OpenWalnut -- Version: " << W_VERSION <<
" ( http://www.openwalnut.org )"
68 "Copyright 2009-2022 The OpenWalnut Community\n"
69 " 2015-2022 Hochschule Worms\n"
70 " 2009-2022 BSV at Universitaet Leipzig\n"
71 " 2012-2017 Nemtics & Sebastian Eichelbaum\n"
72 " 2009-2013 MPI CBS, Leipzig, Germany\n"
73 "For more information see http://www.openwalnut.org/copying\n"
74 "This program comes with ABSOLUTELY NO WARRANTY.\n"
75 "This is free software, and you are welcome to redistribute it\n"
76 "under the terms of the GNU Lesser General Public License.\n"
77 "You should have received a copy of the GNU Lesser General Public License\n"
78 "along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>." << std::endl;
79 std::cout << std::endl;
81 std::cout <<
"Written by the OpenWalnut Community, Hochschule Worms, Nemtics, BSV@Uni-Leipzig and CNCF@MPI-CBS." << std::endl;
92 int main(
int argc,
char** argv )
97 std::string logFile =
"openwalnut.log";
100 namespace po = boost::program_options;
101 po::options_description desc(
"Options" );
106 (
"help,h",
"Prints this help message" )
107 (
"version,v",
"Prints the version information" )
108 (
"log,l", po::value< std::string >(), ( std::string(
"The log-file to use. If not specified, \"" ) + logFile +
109 std::string(
"\" is used in the current directory." ) ).c_str() )
110 (
"interp,i", po::value< std::string >(),
"The interpreter to use." )
111 (
"file,f", po::value< std::vector< std::string > >()->multitoken(),
"The script file to load and its parameters." );
113 boost::program_options::variables_map optionsMap;
116 po::store( po::command_line_parser( argc, argv ).options( desc ).run(), optionsMap );
118 catch(
const po::error &e )
120 std::cerr << e.what() << std::endl;
124 po::notify( optionsMap );
127 if( optionsMap.count(
"version" ) )
132 else if( optionsMap.count(
"help" ) || ( optionsMap.count(
"interp" ) == 0 && optionsMap.count(
"file" ) == 0 ) )
136 std::cout <<
"OpenWalnut is a highly expansible visualization system with focus on brain- and neurological data." << std::endl
138 <<
"Usage: openwalnut [OPTION]... [FILE]..." << std::endl
142 <<
"Examples:" << std::endl
143 <<
" openwalnut-script -i lua \t\tStartup OpenWalnut in lua interpreter mode." << std::endl
144 <<
" openwalnut-script -i python \t\tStartup OpenWalnut in python interpreter mode." << std::endl
146 <<
" openwalnut-script -f doSth.py\t\tStart OpenWalnut and execute the doSth.py python script." << std::endl
160 if( optionsMap.count(
"log" ) )
162 logFile = optionsMap[
"log"].as< std::string >();
166 boost::filesystem::path logPath( logFile );
167 logPath = boost::filesystem::system_complete( logPath );
168 bool fallbackLog =
false;
169 boost::filesystem::path fallbackLogFile = tempFilename(
"OpenWalnutLog-%%%%%%%%.log" );
172 std::ofstream crashLogFile( logPath.string().c_str() );
173 if( !crashLogFile.is_open() )
176 crashLogFile.open( fallbackLogFile.string().c_str() );
181 if( crashLogFile.is_open() )
190 wlog::info(
"Walnut" ) <<
"Using the file \"" << logPath.string() <<
"\" for logging.";
194 wlog::info(
"Walnut" ) <<
"Using the fallback file \"" << fallbackLogFile.string() <<
"\" for logging.";
199 wlog::warn(
"Walnut" ) <<
"Could not open \"" << logPath.string() <<
"\" for writing. You will have no log-file.";
203 wlog::info(
"Walnut" ) <<
"Version: " << W_VERSION;
207 std::shared_ptr< WScriptUI > ui(
new WScriptUI( argc, argv, optionsMap ) );
208 int result = ui->run();
210 std::cout <<
"Closed OpenWalnut smoothly. Goodbye!" << std::endl;
Class implementing a capsule for an output stream and the needed level and format information.
std::shared_ptr< WLogStream > SharedPtr
shared pointer type
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
void addStream(WLogStream::SharedPtr s)
Adds a new stream to the logger.
Implements a UI that executes scripts.
static void installSignalHandler()
Installs this exception as signal handler for SIGSEGV.
static void setThisThreadName(std::string name)
Static function to set the name of the calling thread.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
WStreamedLogger info(const std::string &source)
Logging an information message.