ls_lua_api_t * ls_lua_dl_loadModule( const char * name, char * errbuf ) { register ls_lua_api_t *dlp; errbuf[0] = 0; if ( (dlp = findModuleByName( name )) ) { return dlp; } dlp = ( ls_lua_api_t * )malloc( sizeof( ls_lua_api_t ) + strlen( name ) + 1 ); if ( !dlp ) { snprintf( errbuf, MAX_ERRBUF_SIZE, "NO MEMORY" ); return NULL; } if ( !( dlp->moduleName = strdup( name ) ) ) { snprintf( errbuf, MAX_ERRBUF_SIZE, "NO MEMORY" ); free( dlp ); return NULL; } if ( loadModule( dlp, errbuf ) ) { /* problem in load module */ free( dlp->moduleName ); free( dlp ); return NULL; } return dlp; }
CommandLineModuleMap::const_iterator CommandLineModuleManager::Impl::findModuleFromBinaryName( const ProgramInfo &programInfo) const { std::string binaryName = programInfo.invariantProgramName(); if (binaryName == programInfo.realBinaryName()) { return modules_.end(); } if (binaryName.compare(0, 2, "g_") == 0) { binaryName.erase(0, 2); } return findModuleByName(binaryName); }
CommandLineModuleInterface * CommandLineModuleManager::Impl::processCommonOptions( CommandLineCommonOptionsHolder *optionsHolder, int *argc, char ***argv) { // Check if we are directly invoking a certain module. CommandLineModuleInterface *module = singleModule_; // TODO: It would be nice to propagate at least the -quiet option to // the modules so that they can also be quiet in response to this. if (module == NULL) { // If not in single-module mode, process options to the wrapper binary. // TODO: Ideally, this could be done by CommandLineParser. int argcForWrapper = 1; while (argcForWrapper < *argc && (*argv)[argcForWrapper][0] == '-') { ++argcForWrapper; } if (argcForWrapper > 1) { CommandLineParser(optionsHolder->options()) .parse(&argcForWrapper, *argv); } // If no action requested and there is a module specified, process it. if (argcForWrapper < *argc && !optionsHolder->shouldIgnoreActualModule()) { const char *moduleName = (*argv)[argcForWrapper]; CommandLineModuleMap::const_iterator moduleIter = findModuleByName(moduleName); if (moduleIter == modules_.end()) { std::string message = formatString("'%s' is not a GROMACS command.", moduleName); GMX_THROW(InvalidInputError(message)); } module = moduleIter->second.get(); *argc -= argcForWrapper; *argv += argcForWrapper; // After this point, argc and argv are the same independent of // which path is taken: (*argv)[0] is the module name. } } if (module != NULL) { if (singleModule_ == NULL) { programContext_.setDisplayName(binaryName_ + " " + module->name()); } // Recognize the common options also after the module name. // TODO: It could be nicer to only recognize -h/-hidden if module is not // null. CommandLineParser(optionsHolder->options()) .skipUnknown(true).parse(argc, *argv); } if (!optionsHolder->finishOptions()) { return NULL; } // If no module specified and no other action, show the help. // Also explicitly specifying -h for the wrapper binary goes here. if (module == NULL || optionsHolder->shouldShowHelp()) { ensureHelpModuleExists(); if (module != NULL) { helpModule_->setModuleOverride(*module); } *argc = 1; module = helpModule_; } if (module == helpModule_) { helpModule_->setShowHidden(optionsHolder->shouldShowHidden()); } return module; }