* The pointed module is owned by the \a modules_ container.
*/
CommandLineHelpModule *helpModule_;
+ //! Whether all stderr output should be suppressed.
+ bool bQuiet_;
};
CommandLineModuleManager::Impl::Impl(const ProgramInfo &programInfo)
- : programInfo_(programInfo), helpModule_(NULL)
+ : programInfo_(programInfo), helpModule_(NULL), bQuiet_(false)
{
}
{
}
+void CommandLineModuleManager::setQuiet(bool bQuiet)
+{
+ impl_->bQuiet_ = bQuiet;
+}
+
void CommandLineModuleManager::addModule(CommandLineModulePointer module)
{
GMX_ASSERT(impl_->modules_.find(module->name()) == impl_->modules_.end(),
int argOffset = 0;
CommandLineModuleMap::const_iterator module
= impl_->findModuleFromBinaryName(impl_->programInfo_);
+ if (!impl_->bQuiet_)
+ {
+ printBinaryInformation(stderr, impl_->programInfo_);
+ }
if (module == impl_->modules_.end())
{
if (argc < 2)
{
impl_->helpModule_->printUsage();
- gmx_thanx(stderr);
+ if (!impl_->bQuiet_)
+ {
+ gmx_thanx(stderr);
+ }
return 2;
}
module = impl_->findModuleByName(argv[1]);
{
fprintf(stderr, "Unknown command: '%s'\n\n", argv[1]);
impl_->helpModule_->printUsage();
- gmx_thanx(stderr);
+ if (!impl_->bQuiet_)
+ {
+ gmx_thanx(stderr);
+ }
return 2;
}
int rc = module->second->run(argc - argOffset, argv + argOffset);
- gmx_thanx(stderr);
+ if (!impl_->bQuiet_)
+ {
+ gmx_thanx(stderr);
+ }
return rc;
}
{
const gmx::ProgramInfo &programInfo =
gmx::ProgramInfo::init("gmx", argc, argv);
- CopyRight(stderr, argv[0]);
try
{
gmx::CommandLineModuleManager manager(programInfo);
explicit CommandLineModuleManager(const ProgramInfo &programInfo);
~CommandLineModuleManager();
+ /*! \brief
+ * Sets the module manager to quiet mode: don't print anything.
+ *
+ * \param[in] bQuiet Whether the module manager should remain silent.
+ *
+ * Normally, the module manager prints out some information to stderr
+ * before it starts the module and after it finishes. This removes
+ * that output, which is useful in particular for unit tests so that
+ * they don't spam stderr.
+ */
+ void setQuiet(bool bQuiet);
+
/*! \brief
* Adds a given module to this manager.
*
manager_.reset();
programInfo_.reset(new gmx::ProgramInfo("g_test", args.argc(), args.argv()));
manager_.reset(new gmx::CommandLineModuleManager(*programInfo_));
+ manager_->setQuiet(true);
}
MockModule &
#include "main.h"
#include "macros.h"
+#include "gromacs/utility/programinfo.h"
+
/* We use the same defines as in mvdata.c here */
#define block_bc(cr, d) gmx_bcast( sizeof(d), &(d), (cr))
#define nblock_bc(cr, nr, d) gmx_bcast((nr)*sizeof((d)[0]), (d), (cr))
#define NFILE asize(fnm)
cr = init_par(&argc, &argv);
+ gmx::ProgramInfo::init(argc, argv);
#ifdef GMX_LIB_MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
- if (MASTER(cr))
- {
- CopyRight(stderr, argv[0]);
- }
-
- PCA_Flags = PCA_NOEXIT_ON_ARGS;
+ PCA_Flags = PCA_NOEXIT_ON_ARGS | PCA_STANDALONE;
PCA_Flags |= (MASTER(cr) ? 0 : PCA_QUIET);
parse_common_args(&argc, argv, PCA_Flags,
#include "gromacs/legacyheaders/vec.h"
#include "gromacs/fft/fft.h"
+#include "gromacs/utility/programinfo.h"
#include "buildinfo.h"
sfree(tmpstr);
}
-void CopyRight(FILE *out, const char *szProgram)
+void CopyRight(FILE *out)
{
- static const char * CopyrightText[] = {
+ static const char * const CopyrightText[] = {
"Written by Emile Apol, Rossen Apostolov, Herman J.C. Berendsen,",
"Aldert van Buuren, Pär Bjelkmar, Rudi van Drunen, Anton Feenstra, ",
"Gerrit Groenhof, Peter Kasson, Per Larsson, Pieter Meulenhoff, ",
"Michael Shirts, Alfons Sijbers, Peter Tieleman,\n",
"Berk Hess, David van der Spoel, and Erik Lindahl.\n",
"Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
- "Copyright (c) 2001-2010, The GROMACS development team at",
+ "Copyright (c) 2001-2013, The GROMACS development team at",
"Uppsala University & The Royal Institute of Technology, Sweden.",
"check out http://www.gromacs.org for more information.\n"
};
- static const char * LicenseText[] = {
+ static const char * const LicenseText[] = {
"This program is free software; you can redistribute it and/or",
"modify it under the terms of the GNU Lesser General Public License",
"as published by the Free Software Foundation; either version 2.1",
"of the License, or (at your option) any later version."
};
- /* Dont change szProgram arbitrarily - it must be argv[0], i.e. the
- * name of a file. Otherwise, we won't be able to find the library dir.
- */
-
#define NCR (int)asize(CopyrightText)
/* TODO: Is this exception still needed? */
#ifdef GMX_FAHCORE
#define NLICENSE (int)asize(LicenseText)
#endif
- char buf[256], tmpstr[1024];
+ char tmpstr[1024];
int i;
-#ifdef GMX_FAHCORE
- set_program_name("Gromacs");
-#else
- set_program_name(szProgram);
-#endif
-
ster_print(out, "G R O M A C S");
fprintf(out, "\n");
sp_print(out, tmpstr);
fprintf(out, "\n");
- ster_print(out, GromacsVersion());
- fprintf(out, "\n");
-
- if (getenv("GMX_NO_CREDITS"))
- {
- return;
- }
-
- /* fprintf(out,"\n");*/
-
- /* sp_print(out,"PLEASE NOTE: THIS IS A BETA VERSION\n");
-
- fprintf(out,"\n"); */
-
for (i = 0; (i < NCR); i++)
{
sp_print(out, CopyrightText[i]);
{
sp_print(out, LicenseText[i]);
}
-
- fprintf(out, "\n");
-
- snprintf(buf, 256, "%s", Program());
-#ifdef GMX_DOUBLE
- strcat(buf, " (double precision)");
-#endif
- ster_print(out, buf);
- fprintf(out, "\n");
}
#ifdef GMX_GPU
gmx_print_version_info_gpu(fp);
#endif
+}
+
+namespace gmx
+{
+void printBinaryInformation(FILE *fp, const ProgramInfo &programInfo)
+{
+ const char *precisionString = "";
+#ifdef GMX_DOUBLE
+ precisionString = " (double precision)";
+#endif
+ const std::string &name = programInfo.programName();
+ fprintf(fp, "GROMACS: %s, %s%s\n", name.c_str(),
+ GromacsVersion(), precisionString);
+ fprintf(fp, "Executable: %s\n", programInfo.programNameWithPath().c_str());
+ fprintf(fp, "Command line:\n %s\n", programInfo.commandLine().c_str());
+ fprintf(fp, "\n");
}
+
+} // namespace gmx
GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
}
-void set_program_name(const char *argvzero)
-{
- // The negative argc is a hack to make the ProgramInfo overridable in
- // parse_common_args(), where the full command-line is known.
- gmx::ProgramInfo::init(-1, &argvzero);
-}
-
/* utility functions */
gmx_bool bRmod_fd(double a, double b, double c, gmx_bool bDouble)
};
#define NPCA_PA asize(pca_pa)
FILE *fp;
- gmx_bool bPrint, bExit, bXvgr;
+ gmx_bool bExit, bXvgr;
int i, j, k, npall, max_pa;
+ // Handle the flags argument, which is a bit field
+ // The FF macro returns whether or not the bit is set
#define FF(arg) ((Flags & arg) == arg)
+ // Ensure that the program info is initialized; if already done, returns
+ // the already initialized object.
+ const gmx::ProgramInfo &programInfo = gmx::ProgramInfo::init(*argc, argv);
+ if (FF(PCA_STANDALONE))
+ {
+ gmx::printBinaryInformation(stderr, programInfo);
+ }
/* Check for double arguments */
for (i = 1; (i < *argc); i++)
{
}
}
debug_gmx();
- gmx::ProgramInfo::init(*argc, argv);
-
- /* Handle the flags argument, which is a bit field
- * The FF macro returns whether or not the bit is set
- */
- bPrint = !FF(PCA_SILENT);
/* Check ALL the flags ... */
max_pa = NPCA_PA + EXTRA_PA + npargs+1;
write_man(stderr, "help", output_env_get_program_name(*oenv),
ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
}
- else if (bPrint)
+ else
{
pr_fns(stderr, nfile, fnm);
print_pargs(stderr, npall, all_pa, FALSE);
void
gmx_print_version_info(FILE *fp);
-void
-CopyRight(FILE *out, const char *szProgram);
-
-
/* For both bromacs() and cool_quote() you have to provide a pointer to
* a string of reasonable length (say 256) and the string length. This
* is necessary to make the routines threadsafe and avoid allocating
#ifdef __cplusplus
}
+
+namespace gmx
+{
+
+class ProgramInfo;
+
+/*! \brief
+ * Print basic information about the executable.
+ *
+ * \param fp Where to print the information to.
+ * \param[in] programInfo Program information object to use.
+ */
+void printBinaryInformation(FILE *fp, const ProgramInfo &programInfo);
+
+} // namespace gmx;
+
#endif
#endif /* _copyright_h */
* directory from its location!
*/
const char *Program(void);
-void set_program_name(const char *argvzero);
/* Id. without leading directory */
const char *ShortProgram(void);
/* set time unit for output */
#define PCA_KEEP_ARGS (1<<8)
/* keep parsed args in argv (doesn't make sense without NOEXIT_ON_ARGS) */
-#define PCA_SILENT (1<<9)
-/* don't print options by default */
+#define PCA_STANDALONE (1<<9)
+/* add options for standalone programs and print a header */
#define PCA_CAN_SET_DEFFNM (1<<10)
/* does something for non-master mdrun nodes */
#define PCA_NOEXIT_ON_ARGS (1<<11)
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programinfo.h"
namespace gmx
{
if (impl_->bStandalone_)
{
- CopyRight(stderr, argv[0]);
+ printBinaryInformation(stderr, ProgramInfo::getInstance());
}
SelectionCollection selections;
{
//! Mutex for updates to the global program info objects.
tMPI::mutex g_programInfoMutex;
-//! Partially filled program info, needed to support set_program_name().
-boost::scoped_ptr<ProgramInfo> g_partialProgramInfo;
//! Global program info; stores the object initialized with ProgramInfo::init().
boost::scoped_ptr<ProgramInfo> g_programInfo;
} // namespace
tMPI::lock_guard<tMPI::mutex> lock(g_programInfoMutex);
if (g_programInfo.get() == NULL)
{
- if (g_partialProgramInfo.get() != NULL)
- {
- return *g_partialProgramInfo;
- }
static ProgramInfo fallbackInfo;
return fallbackInfo;
}
tMPI::lock_guard<tMPI::mutex> lock(g_programInfoMutex);
if (g_programInfo.get() == NULL)
{
- // TODO: Remove this hack with negative argc once there is no need for
- // set_program_name().
- if (argc < 0)
- {
- if (g_partialProgramInfo.get() == NULL)
- {
- g_partialProgramInfo.reset(
- new ProgramInfo(realBinaryName, -argc, argv));
- }
- return *g_partialProgramInfo;
- }
g_programInfo.reset(new ProgramInfo(realBinaryName, argc, argv));
}
return *g_programInfo;
#include "rama.bm"
#include "nrama.h"
+#include "gromacs/utility/programinfo.h"
+
#define MAXDEG 360
enum {
};
#define NFILE asize(fnm)
- CopyRight(stderr, argv[0]);
- parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, 0, NULL,
- asize(desc), desc, 0, NULL, &oenv);
+ gmx::ProgramInfo::init(argc, argv);
+ parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_STANDALONE, NFILE, fnm,
+ 0, NULL, asize(desc), desc, 0, NULL, &oenv);
if ((x11 = GetX11(&argc, argv)) == NULL)
};
#define NFILE asize(fnm)
- CopyRight(stderr, argv[0]);
- parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm,
+ gmx::ProgramInfo::init(argc, argv);
+ parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_STANDALONE, NFILE, fnm,
0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv);
if ((x11 = GetX11(&argc, argv)) == NULL)
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
*/
-#include "gromacs/legacyheaders/copyrite.h"
-
#include "gromacs/commandline/cmdlinemodulemanager.h"
#include "gromacs/selection/selectioncollection.h"
#include "gromacs/trajectoryanalysis/modules.h"
{
const gmx::ProgramInfo &info =
gmx::ProgramInfo::init("gmx", argc, argv);
- // TODO: With the addition of ProgramInfo above, this no longer needs to
- // be here, so think where it would best go.
- CopyRight(stderr, argv[0]);
try
{
gmx::CommandLineModuleManager manager(info);
#include "gromacs/legacyheaders/statutil.h"
#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/utility/programinfo.h"
+
int main(int argc, char *argv[])
{
const char *desc[] = {
cr = init_par(&argc, &argv);
+ gmx::ProgramInfo::init(argc, argv);
- if (MASTER(cr))
- {
- CopyRight(stderr, argv[0]);
- }
-
- PCA_Flags = (PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET));
+ PCA_Flags = (PCA_CAN_SET_DEFFNM | PCA_STANDALONE | (MASTER(cr) ? 0 : PCA_QUIET));
/* Comment this in to do fexist calls only on master
* works not with rerun or tables at the moment
{
gmx_log_open(ftp2fn(efLOG, NFILE, fnm), cr,
!bSepPot, Flags & MD_APPENDFILES, &fplog);
- CopyRight(fplog, argv[0]);
please_cite(fplog, "Hess2008b");
please_cite(fplog, "Spoel2005a");
please_cite(fplog, "Lindahl2001a");