Allow runAsMainSingleModule to be called more than once
[alexxy/gromacs.git] / src / gromacs / commandline / cmdlineinit.cpp
index 4f17e42e74ca908c203c994e08a1095106f8b30a..003ad846c901535989875ef5900e9af1d69eeafd 100644 (file)
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_commandline
  */
-#include "gromacs/commandline/cmdlineinit.h"
+#include "gmxpre.h"
+
+#include "cmdlineinit.h"
+
+#include "config.h"
 
 #include <cstring>
 
 #include <boost/scoped_ptr.hpp>
 
+#include "gromacs/commandline/cmdlinemodulemanager.h"
+#include "gromacs/commandline/cmdlineprogramcontext.h"
 #include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/types/commrec.h"
-
-#include "gromacs/commandline/cmdlineprogramcontext.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/init.h"
 #include "gromacs/utility/programcontext.h"
+#include "gromacs/utility/smalloc.h"
 
 namespace gmx
 {
@@ -136,4 +140,22 @@ void finalizeForCommandLine()
     g_commandLineContext.reset();
 }
 
+int processExceptionAtExitForCommandLine(const std::exception &ex)
+{
+    int rc = processExceptionAtExit(ex); //Currently this aborts for GMX_LIB_MPI
+    finalizeForCommandLine();            //thus this MPI_Finalize doesn't matter
+    return rc;
+}
+
+int runCommandLineModule(int argc, char *argv[],
+                         CommandLineModuleInterface *module)
+{
+    return gmx::CommandLineModuleManager::runAsMainSingleModule(argc, argv, module);
+}
+
 } // namespace gmx
+
+int gmx_run_cmain(int argc, char *argv[], int (*mainFunction)(int, char *[]))
+{
+    return gmx::CommandLineModuleManager::runAsMainCMain(argc, argv, mainFunction);
+}