bool Command::Execute( argList_t& args ) { lua_State *L = **lua; lua->PushReference( ref ); argList_t::const_iterator iter = args.begin(); for ( ; iter != args.end(); ++iter ) lua_pushlstring( L, iter->c_str(), iter->size() ); return lua->PCallStackVoid( args.size() ); }
int InitProcess( argList_t& args ) { cout << "IDPickerQonvert " << idpQonvert::Version::str() << " (" << idpQonvert::Version::LastModified() << ")\n" << "IDPickerCore " << IDPicker::Version::str() << " (" << IDPicker::Version::LastModified() << ")\n" << "FreiCore " << freicore::Version::str() << " (" << freicore::Version::LastModified() << ")\n" << endl; string usage = "Usage: " + lexical_cast<string>(bfs::path(args[0]).filename()) + " [optional arguments] <analyzed data filemask> [<another filemask> ...]\n" "Optional arguments:\n" "-b <batch filepath> : specify a file which lists the filepaths to process line-by-line\n" "-cfg <config filepath> : specify a configuration file other than the default\n" "-workdir <working directory> : change working directory\n" "-cpus <value> : force use of <value> worker threads\n" "-ignoreConfigErrors : ignore errors in configuration file or the command-line\n" "-AnyParameterName <value> : override the value of the given parameter to <value>\n" "-dump : show runtime configuration settings before starting the run\n"; bool ignoreConfigErrors = false; string logFilepath; g_numWorkers = GetNumProcessors(); // First set the working directory, if provided for( size_t i=1; i < args.size(); ++i ) { if( args[i] == "-workdir" && i+1 <= args.size() ) { bfs::current_path(args[i + 1]); args.erase( args.begin() + i ); } else if( args[i] == "-cpus" && i+1 <= args.size() ) { g_numWorkers = atoi( args[i+1].c_str() ); args.erase( args.begin() + i ); } else if( args[i] == "-ignoreConfigErrors" ) { ignoreConfigErrors = true; } else if (args[i] == "-LogFilepath") { logFilepath = args[i+1]; continue; } else continue; args.erase( args.begin() + i ); --i; } g_rtConfig = new RunTimeConfig(!ignoreConfigErrors); g_rtSharedConfig = (BaseRunTimeConfig*) g_rtConfig; g_rtConfig->LogFilepath = logFilepath; boost::log::formatter fmt = expr::stream << expr::attr<MessageSeverity::domain, severity_tag>("Severity") << expr::smessage; // Initialize sinks typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink; boost::shared_ptr<text_sink> sink = boost::make_shared<text_sink>(); // errors always go to console sink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&cerr, boost::null_deleter())); sink->set_formatter(fmt); sink->set_filter(severity >= MessageSeverity::Error); boost::log::core::get()->add_sink(sink); sink->locked_backend()->auto_flush(true); // Add attributes boost::log::add_common_attributes(); vector<string> extraFilepaths; for( size_t i=1; i < args.size(); ++i ) { if( args[i] == "-cfg" && i+1 <= args.size() ) { if( g_rtConfig->initializeFromFile( args[i+1] ) ) { BOOST_LOG_SEV(logSource::get(), MessageSeverity::Error) << "could not find runtime configuration at \"" << args[i+1] << "\"." << endl; return QONVERT_ERROR_RUNTIME_CONFIG_FILE_FAILURE; } args.erase( args.begin() + i ); } else if( args[i] == "-b" && i+1 <= args.size() ) { // read filepaths from file if( !bfs::exists(args[i+1]) ) { BOOST_LOG_SEV(logSource::get(), MessageSeverity::Error) << "could not find list file at \"" << args[i + 1] << "\"." << endl; return QONVERT_ERROR_RUNTIME_CONFIG_FILE_FAILURE; } ifstream listFile(args[i+1].c_str()); string line; while (getline(listFile, line)) extraFilepaths.push_back(line); args.erase( args.begin() + i ); } else continue; args.erase( args.begin() + i ); --i; } if( g_rtConfig->inputFilepaths.empty() && args.size() < 2 ) { BOOST_LOG_SEV(logSource::get(), MessageSeverity::Error) << "not enough arguments.\n\n" << usage << endl; return QONVERT_ERROR_NOT_ENOUGH_ARGUMENTS; } if( !g_rtConfig->initialized() ) { if( g_rtConfig->initializeFromFile() ) { BOOST_LOG_SEV(logSource::get(), MessageSeverity::Warning) << "could not find the default configuration file (hard-coded defaults in use)." << endl; } } // Command line overrides happen after config file has been distributed but before PTM parsing RunTimeVariableMap vars = g_rtConfig->getVariables(); for( RunTimeVariableMap::iterator itr = vars.begin(); itr != vars.end(); ++itr ) { string varName; varName += "-" + itr->first; for( size_t i=1; i < args.size(); ++i ) { if( args[i] == varName && i+1 < args.size() ) { //cout << varName << " " << itr->second << " " << args[i+1] << endl; itr->second = args[i+1]; args.erase( args.begin() + i ); args.erase( args.begin() + i ); --i; } } } try { g_rtConfig->setVariables(vars); } catch (runtime_error& e) { string error = bal::replace_all_copy(string(e.what()), "Error! ", ""); throw runtime_error(error); } sink = boost::make_shared<text_sink>(); if (g_rtConfig->LogFilepath.empty()) { sink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&cout, boost::null_deleter())); // if no logfile is set, send messages to console sink->set_filter(severity < MessageSeverity::Error); // but don't send errors to the console twice } else { sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(g_rtConfig->LogFilepath.c_str())); sink->set_filter(severity >= g_rtConfig->LogLevel.index()); // NOTE: use index() to avoid delayed evaluation of expression } fmt = expr::stream << expr::attr<MessageSeverity::domain, severity_tag>("Severity") << expr::smessage; sink->set_formatter(fmt); boost::log::core::get()->add_sink(sink); for( size_t i=1; i < args.size(); ++i ) { if( args[i] == "-dump" ) { g_rtConfig->dump(); args.erase( args.begin() + i ); --i; } } for( size_t i=1; i < args.size(); ++i ) { if( args[i][0] == '-' ) { if (!ignoreConfigErrors) { BOOST_LOG_SEV(logSource::get(), MessageSeverity::Error) << "unrecognized parameter \"" << args[i] << "\"" << endl; return 1; } BOOST_LOG_SEV(logSource::get(), MessageSeverity::Warning) << "ignoring unrecognized parameter \"" << args[i] << "\"" << endl; args.erase( args.begin() + i ); --i; } } if (args.size() == 1) { if (g_pid == 0) BOOST_LOG_SEV(logSource::get(), MessageSeverity::Error) << "no data sources specified.\n\n" << usage << endl; return 1; } args.insert(args.end(), extraFilepaths.begin(), extraFilepaths.end()); return 0; }