Fine-tune copyright printing.
authorTeemu Murtola <teemu.murtola@gmail.com>
Mon, 29 Jul 2013 04:46:30 +0000 (07:46 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 24 Aug 2013 18:22:44 +0000 (20:22 +0200)
Based on discussion in earlier changes, made the copyright on by
default.  It is now possible to suppress it while keeping other parts of
the startup header with -nocopyright.

Simplify the copyright printing code and make the output more in line
with the rest of the startup header (left-aligned etc.).  Move the
copyright to the beginning of the header to have all diagnostic
information available under it; that makes it easier for the user (and
for us in bug reports) to spot all the relevant information.

Also adjust the wording of the license text; LGPL does not automatically
place a user program that calls GROMACS under the same license, so
changed "This program" to "GROMACS".  Made a similar clarification to
the "Written by" text.

Part of #1209.

Change-Id: If104074995db891702dd9eb410fe811408add4ad

src/gromacs/commandline/cmdlinemodulemanager.cpp
src/gromacs/gmxlib/copyrite.cpp

index 9be10392f905354ffe9bafd8efe7afdd03445de1..68e16ef9960c5ce5675724bf7835248dd4fdccc0 100644 (file)
@@ -383,7 +383,7 @@ class CMainCommandLineModule : public CommandLineModuleInterface
 
 };
 
-} // namespace
+}   // namespace
 
 /********************************************************************
  * CommandLineModuleManager::Impl
@@ -483,6 +483,7 @@ CommandLineModuleManager::Impl::Impl(ProgramInfo *programInfo)
     : programInfo_(*programInfo), helpModule_(NULL), singleModule_(NULL),
       bQuiet_(false), bStdOutInfo_(false)
 {
+    binaryInfoSettings_.copyright(true);
 }
 
 CommandLineModuleMap::const_iterator
@@ -526,7 +527,7 @@ CommandLineModuleManager::Impl::processCommonOptions(int *argc, char ***argv)
 
     bool bHelp      = false;
     bool bVersion   = false;
-    bool bCopyright = false;
+    bool bCopyright = true;
     // TODO: Print the common options into the help.
     // 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.
@@ -560,7 +561,7 @@ CommandLineModuleManager::Impl::processCommonOptions(int *argc, char ***argv)
             CommandLineParser(&options).parse(&argcForWrapper, *argv);
         }
         // If no action requested and there is a module specified, process it.
-        if (argcForWrapper < *argc && !bHelp && !bVersion && !bCopyright)
+        if (argcForWrapper < *argc && !bHelp && !bVersion)
         {
             const char *moduleName = (*argv)[argcForWrapper];
             CommandLineModuleMap::const_iterator moduleIter
@@ -589,7 +590,7 @@ CommandLineModuleManager::Impl::processCommonOptions(int *argc, char ***argv)
     options.finish();
     binaryInfoSettings_.extendedInfo(bVersion);
     binaryInfoSettings_.copyright(bCopyright);
-    if (bVersion || bCopyright)
+    if (bVersion)
     {
         bQuiet_      = false;
         bStdOutInfo_ = true;
@@ -655,7 +656,7 @@ void CommandLineModuleManager::addHelpTopic(HelpTopicPointer topic)
 int CommandLineModuleManager::run(int argc, char *argv[])
 {
     CommandLineModuleInterface *module;
-    const bool bMaster = (!gmx_mpi_initialized() || gmx_node_rank() == 0);
+    const bool                  bMaster = (!gmx_mpi_initialized() || gmx_node_rank() == 0);
     try
     {
         module = impl_->processCommonOptions(&argc, &argv);
@@ -664,7 +665,8 @@ int CommandLineModuleManager::run(int argc, char *argv[])
     {
         if (bMaster && !impl_->bQuiet_)
         {
-            printBinaryInformation(stderr, impl_->programInfo_);
+            printBinaryInformation(stderr, impl_->programInfo_,
+                                   impl_->binaryInfoSettings_);
         }
         throw;
     }
index 6e0794a8f3d8731a5f31f2c78bea4e7aa294fa6f..99229e00529ada12fed1ee71e0ba6fc1ff29a119 100644 (file)
@@ -78,32 +78,6 @@ static gmx_bool be_cool(void)
 #endif
 }
 
-static void space(FILE *out, int n)
-{
-    fprintf(out, "%*s", n, "");
-}
-
-static void sp_print(FILE *out, const char *s)
-{
-    int slen;
-
-    slen = strlen(s);
-    space(out, (80-slen)/2);
-    fprintf(out, "%s\n", s);
-}
-
-static void ster_print(FILE *out, const char *s)
-{
-    int  slen;
-    char buf[128];
-
-    snprintf(buf, 128, ":-)  %s  (-:", s);
-    slen = strlen(buf);
-    space(out, (80-slen)/2);
-    fprintf(out, "%s\n", buf);
-}
-
-
 static void pukeit(const char *db, const char *defstring, char *retstring,
                    int retsize, int *cqnum)
 {
@@ -179,55 +153,45 @@ void cool_quote(char *retstring, int retsize, int *cqnum)
     sfree(tmpstr);
 }
 
-static void CopyRight(FILE *out)
+static void printCopyright(FILE *fp)
 {
     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, ",
-        "Teemu Murtola, Szilard Pall, Sander Pronk, Roland Schulz, ",
+        "GROMACS is 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,",
+        "Teemu Murtola, Szilard Pall, Sander Pronk, Roland Schulz,",
         "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-2013, The GROMACS development team at",
         "Uppsala University & The Royal Institute of Technology, Sweden.",
-        "check out http://www.gromacs.org for more information.\n"
+        "check out http://www.gromacs.org for more information."
     };
 
     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",
+        "GROMACS 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."
     };
 
 #define NCR (int)asize(CopyrightText)
-/* TODO: Is this exception still needed? */
+// FAH has an exception permission from LGPL to allow digital signatures in Gromacs.
 #ifdef GMX_FAHCORE
-#define NLICENSE 0 /*FAH has an exception permission from LGPL to allow digital signatures in Gromacs*/
+#define NLICENSE 0
 #else
 #define NLICENSE (int)asize(LicenseText)
 #endif
 
-    char tmpstr[1024];
-    int  i;
-
-    // TODO: Consider making the output more compact to fit better with
-    // other information written by printBinaryInformation().
-    ster_print(out, "G  R  O  M  A  C  S");
-    fprintf(out, "\n");
-
-    bromacs(tmpstr, 1023);
-    sp_print(out, tmpstr);
-    fprintf(out, "\n");
-
-    for (i = 0; (i < NCR); i++)
+    for (int i = 0; i < NCR; ++i)
     {
-        sp_print(out, CopyrightText[i]);
+        fprintf(fp, "%s\n", CopyrightText[i]);
     }
-    for (i = 0; (i < NLICENSE); i++)
+    fprintf(fp, "\n");
+    for (int i = 0; i < NLICENSE; ++i)
     {
-        sp_print(out, LicenseText[i]);
+        fprintf(fp, "%s\n", LicenseText[i]);
     }
 }
 
@@ -711,19 +675,30 @@ void printBinaryInformation(FILE *fp, const ProgramInfo &programInfo,
     {
         fprintf(fp, "%sCreated by:%s\n", prefix, suffix);
     }
-    fprintf(fp, "%sGROMACS:    %s, %s%s%s\n", prefix, name.c_str(),
-            GromacsVersion(), precisionString, suffix);
-    fprintf(fp, "%sExecutable: %s%s\n", prefix,
-            programInfo.programNameWithPath().c_str(), suffix);
-    fprintf(fp, "%sCommand line:%s\n%s  %s%s\n",
-            prefix, suffix, prefix, programInfo.commandLine().c_str(), suffix);
     if (settings.bCopyright_)
     {
         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
                            "Prefix/suffix not supported with copyright");
+        // This line is printed again after the copyright notice to make it
+        // appear together with all the other information, so that it is not
+        // necessary to read stuff above the copyright notice.
+        // The line above the copyright notice puts the copyright notice is
+        // context, though.
+        // TODO: It would be nice to know here whether we are really running a
+        // Gromacs binary or some other binary that is calling Gromacs; we
+        // could then print "%s is part of GROMACS" or some alternative text.
+        fprintf(fp, "%sGROMACS:    %s, %s%s%s\n", prefix, name.c_str(),
+                GromacsVersion(), precisionString, suffix);
+        fprintf(fp, "\n");
+        printCopyright(fp);
         fprintf(fp, "\n");
-        CopyRight(fp);
     }
+    fprintf(fp, "%sGROMACS:    %s, %s%s%s\n", prefix, name.c_str(),
+            GromacsVersion(), precisionString, suffix);
+    fprintf(fp, "%sExecutable: %s%s\n", prefix,
+            programInfo.programNameWithPath().c_str(), suffix);
+    fprintf(fp, "%sCommand line:%s\n%s  %s%s\n",
+            prefix, suffix, prefix, programInfo.commandLine().c_str(), suffix);
     if (settings.bExtendedInfo_)
     {
         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',