Blame lib/version-etc.c

Packit 33f14e
/* Print --version and bug-reporting information in a consistent format.
Packit 33f14e
   Copyright (C) 1999-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Jim Meyering. */
Packit 33f14e
Packit 33f14e
#include <config.h>
Packit 33f14e
Packit 33f14e
/* Specification.  */
Packit 33f14e
#include "version-etc.h"
Packit 33f14e
Packit 33f14e
#include <stdarg.h>
Packit 33f14e
#include <stdio.h>
Packit 33f14e
#include <stdlib.h>
Packit 33f14e
Packit 33f14e
#if USE_UNLOCKED_IO
Packit 33f14e
# include "unlocked-io.h"
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#include "gettext.h"
Packit 33f14e
#define _(msgid) gettext (msgid)
Packit 33f14e
Packit 33f14e
/* If you use AM_INIT_AUTOMAKE's no-define option,
Packit 33f14e
   PACKAGE is not defined.  Use PACKAGE_TARNAME instead.  */
Packit 33f14e
#if ! defined PACKAGE && defined PACKAGE_TARNAME
Packit 33f14e
# define PACKAGE PACKAGE_TARNAME
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
enum { COPYRIGHT_YEAR = 2017 };
Packit 33f14e
Packit 33f14e
/* The three functions below display the --version information the
Packit 33f14e
   standard way.
Packit 33f14e
Packit 33f14e
   If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
Packit 33f14e
   the program.  The formats are therefore:
Packit 33f14e
Packit 33f14e
   PACKAGE VERSION
Packit 33f14e
Packit 33f14e
   or
Packit 33f14e
Packit 33f14e
   COMMAND_NAME (PACKAGE) VERSION.
Packit 33f14e
Packit 33f14e
   The functions differ in the way they are passed author names. */
Packit 33f14e
Packit 33f14e
/* Display the --version information the standard way.
Packit 33f14e
Packit 33f14e
   Author names are given in the array AUTHORS. N_AUTHORS is the
Packit 33f14e
   number of elements in the array. */
Packit 33f14e
void
Packit 33f14e
version_etc_arn (FILE *stream,
Packit 33f14e
                 const char *command_name, const char *package,
Packit 33f14e
                 const char *version,
Packit 33f14e
                 const char * const * authors, size_t n_authors)
Packit 33f14e
{
Packit 33f14e
  if (command_name)
Packit 33f14e
    fprintf (stream, "%s (%s) %s\n", command_name, package, version);
Packit 33f14e
  else
Packit 33f14e
    fprintf (stream, "%s %s\n", package, version);
Packit 33f14e
Packit 33f14e
#ifdef PACKAGE_PACKAGER
Packit 33f14e
# ifdef PACKAGE_PACKAGER_VERSION
Packit 33f14e
  fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
Packit 33f14e
           PACKAGE_PACKAGER_VERSION);
Packit 33f14e
# else
Packit 33f14e
  fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
Packit 33f14e
# endif
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
  /* TRANSLATORS: Translate "(C)" to the copyright symbol
Packit 33f14e
     (C-in-a-circle), if this symbol is available in the user's
Packit 33f14e
     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
Packit 33f14e
  fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
Packit 33f14e
Packit 33f14e
  fputs (_("\
Packit 33f14e
\n\
Packit 33f14e
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
Packit 33f14e
This is free software: you are free to change and redistribute it.\n\
Packit 33f14e
There is NO WARRANTY, to the extent permitted by law.\n\
Packit 33f14e
\n\
Packit 33f14e
"),
Packit 33f14e
         stream);
Packit 33f14e
Packit 33f14e
  switch (n_authors)
Packit 33f14e
    {
Packit 33f14e
    case 0:
Packit 33f14e
      /* The caller must provide at least one author name.  */
Packit 33f14e
      abort ();
Packit 33f14e
    case 1:
Packit 33f14e
      /* TRANSLATORS: %s denotes an author name.  */
Packit 33f14e
      fprintf (stream, _("Written by %s.\n"), authors[0]);
Packit 33f14e
      break;
Packit 33f14e
    case 2:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.  */
Packit 33f14e
      fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
Packit 33f14e
      break;
Packit 33f14e
    case 3:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.  */
Packit 33f14e
      fprintf (stream, _("Written by %s, %s, and %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2]);
Packit 33f14e
      break;
Packit 33f14e
    case 4:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2], authors[3]);
Packit 33f14e
      break;
Packit 33f14e
    case 5:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2], authors[3], authors[4]);
Packit 33f14e
      break;
Packit 33f14e
    case 6:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2], authors[3], authors[4],
Packit 33f14e
               authors[5]);
Packit 33f14e
      break;
Packit 33f14e
    case 7:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2], authors[3], authors[4],
Packit 33f14e
               authors[5], authors[6]);
Packit 33f14e
      break;
Packit 33f14e
    case 8:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("\
Packit 33f14e
Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
Packit 33f14e
                authors[0], authors[1], authors[2], authors[3], authors[4],
Packit 33f14e
                authors[5], authors[6], authors[7]);
Packit 33f14e
      break;
Packit 33f14e
    case 9:
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("\
Packit 33f14e
Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
Packit 33f14e
               authors[0], authors[1], authors[2], authors[3], authors[4],
Packit 33f14e
               authors[5], authors[6], authors[7], authors[8]);
Packit 33f14e
      break;
Packit 33f14e
    default:
Packit 33f14e
      /* 10 or more authors.  Use an abbreviation, since the human reader
Packit 33f14e
         will probably not want to read the entire list anyway.  */
Packit 33f14e
      /* TRANSLATORS: Each %s denotes an author name.
Packit 33f14e
         You can use line breaks, estimating that each author name occupies
Packit 33f14e
         ca. 16 screen columns and that a screen line has ca. 80 columns.  */
Packit 33f14e
      fprintf (stream, _("\
Packit 33f14e
Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
Packit 33f14e
                authors[0], authors[1], authors[2], authors[3], authors[4],
Packit 33f14e
                authors[5], authors[6], authors[7], authors[8]);
Packit 33f14e
      break;
Packit 33f14e
    }
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
/* Display the --version information the standard way.  See the initial
Packit 33f14e
   comment to this module, for more information.
Packit 33f14e
Packit 33f14e
   Author names are given in the NULL-terminated array AUTHORS. */
Packit 33f14e
void
Packit 33f14e
version_etc_ar (FILE *stream,
Packit 33f14e
                const char *command_name, const char *package,
Packit 33f14e
                const char *version, const char * const * authors)
Packit 33f14e
{
Packit 33f14e
  size_t n_authors;
Packit 33f14e
Packit 33f14e
  for (n_authors = 0; authors[n_authors]; n_authors++)
Packit 33f14e
    ;
Packit 33f14e
  version_etc_arn (stream, command_name, package, version, authors, n_authors);
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
/* Display the --version information the standard way.  See the initial
Packit 33f14e
   comment to this module, for more information.
Packit 33f14e
Packit 33f14e
   Author names are given in the NULL-terminated va_list AUTHORS. */
Packit 33f14e
void
Packit 33f14e
version_etc_va (FILE *stream,
Packit 33f14e
                const char *command_name, const char *package,
Packit 33f14e
                const char *version, va_list authors)
Packit 33f14e
{
Packit 33f14e
  size_t n_authors;
Packit 33f14e
  const char *authtab[10];
Packit 33f14e
Packit 33f14e
  for (n_authors = 0;
Packit 33f14e
       n_authors < 10
Packit 33f14e
         && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
Packit 33f14e
       n_authors++)
Packit 33f14e
    ;
Packit 33f14e
  version_etc_arn (stream, command_name, package, version,
Packit 33f14e
                   authtab, n_authors);
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
Packit 33f14e
/* Display the --version information the standard way.
Packit 33f14e
Packit 33f14e
   If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
Packit 33f14e
   the program.  The formats are therefore:
Packit 33f14e
Packit 33f14e
   PACKAGE VERSION
Packit 33f14e
Packit 33f14e
   or
Packit 33f14e
Packit 33f14e
   COMMAND_NAME (PACKAGE) VERSION.
Packit 33f14e
Packit 33f14e
   The authors names are passed as separate arguments, with an additional
Packit 33f14e
   NULL argument at the end.  */
Packit 33f14e
void
Packit 33f14e
version_etc (FILE *stream,
Packit 33f14e
             const char *command_name, const char *package,
Packit 33f14e
             const char *version, /* const char *author1, ...*/ ...)
Packit 33f14e
{
Packit 33f14e
  va_list authors;
Packit 33f14e
Packit 33f14e
  va_start (authors, version);
Packit 33f14e
  version_etc_va (stream, command_name, package, version, authors);
Packit 33f14e
  va_end (authors);
Packit 33f14e
}
Packit 33f14e
Packit 33f14e
void
Packit 33f14e
emit_bug_reporting_address (void)
Packit 33f14e
{
Packit 33f14e
  /* TRANSLATORS: The placeholder indicates the bug-reporting address
Packit 33f14e
     for this package.  Please add _another line_ saying
Packit 33f14e
     "Report translation bugs to <...>\n" with the address for translation
Packit 33f14e
     bugs (typically your translation team's web or email address).  */
Packit 33f14e
  printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
Packit 33f14e
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
Packit 33f14e
  printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
Packit 33f14e
          PACKAGE_PACKAGER_BUG_REPORTS);
Packit 33f14e
#endif
Packit 33f14e
#ifdef PACKAGE_URL
Packit 33f14e
  printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
Packit 33f14e
#else
Packit 33f14e
  printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"),
Packit 33f14e
          PACKAGE_NAME, PACKAGE);
Packit 33f14e
#endif
Packit 33f14e
  fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
Packit 33f14e
         stdout);
Packit 33f14e
}