144b87433SJohn Marino /* Print --version and bug-reporting information in a consistent format.
2*6ea1f93eSDaniel Fojt    Copyright (C) 1999-2018 Free Software Foundation, Inc.
3855caec6SPeter Avalos 
444b87433SJohn Marino    This program is free software: you can redistribute it and/or modify
5855caec6SPeter Avalos    it under the terms of the GNU General Public License as published by
644b87433SJohn Marino    the Free Software Foundation; either version 3 of the License, or
744b87433SJohn Marino    (at your option) any later version.
8855caec6SPeter Avalos 
9855caec6SPeter Avalos    This program is distributed in the hope that it will be useful,
10855caec6SPeter Avalos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11855caec6SPeter Avalos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12855caec6SPeter Avalos    GNU General Public License for more details.
13855caec6SPeter Avalos 
14855caec6SPeter Avalos    You should have received a copy of the GNU General Public License
15*6ea1f93eSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16855caec6SPeter Avalos 
17855caec6SPeter Avalos /* Written by Jim Meyering. */
18855caec6SPeter Avalos 
19855caec6SPeter Avalos #include <config.h>
20855caec6SPeter Avalos 
21855caec6SPeter Avalos /* Specification.  */
22855caec6SPeter Avalos #include "version-etc.h"
23855caec6SPeter Avalos 
24855caec6SPeter Avalos #include <stdarg.h>
25855caec6SPeter Avalos #include <stdio.h>
2644b87433SJohn Marino 
2744b87433SJohn Marino #if USE_UNLOCKED_IO
28855caec6SPeter Avalos # include "unlocked-io.h"
2944b87433SJohn Marino #endif
30855caec6SPeter Avalos 
31855caec6SPeter Avalos #include "gettext.h"
32855caec6SPeter Avalos #define _(msgid) gettext (msgid)
33855caec6SPeter Avalos 
3444b87433SJohn Marino /* If you use AM_INIT_AUTOMAKE's no-define option,
3544b87433SJohn Marino    PACKAGE is not defined.  Use PACKAGE_TARNAME instead.  */
3644b87433SJohn Marino #if ! defined PACKAGE && defined PACKAGE_TARNAME
3744b87433SJohn Marino # define PACKAGE PACKAGE_TARNAME
38855caec6SPeter Avalos #endif
39855caec6SPeter Avalos 
40*6ea1f93eSDaniel Fojt enum { COPYRIGHT_YEAR = 2018 };
41855caec6SPeter Avalos 
4244b87433SJohn Marino /* The three functions below display the --version information the
4344b87433SJohn Marino    standard way.
44855caec6SPeter Avalos 
4544b87433SJohn Marino    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
46855caec6SPeter Avalos    the program.  The formats are therefore:
47855caec6SPeter Avalos 
48855caec6SPeter Avalos    PACKAGE VERSION
49855caec6SPeter Avalos 
50855caec6SPeter Avalos    or
51855caec6SPeter Avalos 
52855caec6SPeter Avalos    COMMAND_NAME (PACKAGE) VERSION.
53855caec6SPeter Avalos 
5444b87433SJohn Marino    The functions differ in the way they are passed author names. */
5544b87433SJohn Marino 
5644b87433SJohn Marino /* Display the --version information the standard way.
5744b87433SJohn Marino 
5844b87433SJohn Marino    Author names are given in the array AUTHORS. N_AUTHORS is the
5944b87433SJohn Marino    number of elements in the array. */
6044b87433SJohn Marino void
version_etc_arn(FILE * stream,const char * command_name,const char * package,const char * version,const char * const * authors,size_t n_authors)6144b87433SJohn Marino version_etc_arn (FILE *stream,
6244b87433SJohn Marino                  const char *command_name, const char *package,
6344b87433SJohn Marino                  const char *version,
6444b87433SJohn Marino                  const char * const * authors, size_t n_authors)
6544b87433SJohn Marino {
6644b87433SJohn Marino   if (command_name)
6744b87433SJohn Marino     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
6844b87433SJohn Marino   else
6944b87433SJohn Marino     fprintf (stream, "%s %s\n", package, version);
7044b87433SJohn Marino 
7144b87433SJohn Marino #ifdef PACKAGE_PACKAGER
7244b87433SJohn Marino # ifdef PACKAGE_PACKAGER_VERSION
7344b87433SJohn Marino   fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
7444b87433SJohn Marino            PACKAGE_PACKAGER_VERSION);
7544b87433SJohn Marino # else
7644b87433SJohn Marino   fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
7744b87433SJohn Marino # endif
7844b87433SJohn Marino #endif
7944b87433SJohn Marino 
8044b87433SJohn Marino   /* TRANSLATORS: Translate "(C)" to the copyright symbol
8144b87433SJohn Marino      (C-in-a-circle), if this symbol is available in the user's
8244b87433SJohn Marino      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
8344b87433SJohn Marino   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
8444b87433SJohn Marino 
8544b87433SJohn Marino   fputs (_("\
8644b87433SJohn Marino \n\
87*6ea1f93eSDaniel Fojt License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n\
8844b87433SJohn Marino This is free software: you are free to change and redistribute it.\n\
8944b87433SJohn Marino There is NO WARRANTY, to the extent permitted by law.\n\
9044b87433SJohn Marino \n\
9144b87433SJohn Marino "),
9244b87433SJohn Marino          stream);
9344b87433SJohn Marino 
9444b87433SJohn Marino   switch (n_authors)
9544b87433SJohn Marino     {
9644b87433SJohn Marino     case 0:
97*6ea1f93eSDaniel Fojt       /* No authors are given.  The caller should output authorship
98*6ea1f93eSDaniel Fojt          info after calling this function.  */
99*6ea1f93eSDaniel Fojt       break;
10044b87433SJohn Marino     case 1:
10144b87433SJohn Marino       /* TRANSLATORS: %s denotes an author name.  */
10244b87433SJohn Marino       fprintf (stream, _("Written by %s.\n"), authors[0]);
10344b87433SJohn Marino       break;
10444b87433SJohn Marino     case 2:
10544b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.  */
10644b87433SJohn Marino       fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
10744b87433SJohn Marino       break;
10844b87433SJohn Marino     case 3:
10944b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.  */
11044b87433SJohn Marino       fprintf (stream, _("Written by %s, %s, and %s.\n"),
11144b87433SJohn Marino                authors[0], authors[1], authors[2]);
11244b87433SJohn Marino       break;
11344b87433SJohn Marino     case 4:
11444b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
11544b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
11644b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
11744b87433SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
11844b87433SJohn Marino                authors[0], authors[1], authors[2], authors[3]);
11944b87433SJohn Marino       break;
12044b87433SJohn Marino     case 5:
12144b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
12244b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
12344b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
12444b87433SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
12544b87433SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4]);
12644b87433SJohn Marino       break;
12744b87433SJohn Marino     case 6:
12844b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
12944b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
13044b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
13144b87433SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
13244b87433SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
13344b87433SJohn Marino                authors[5]);
13444b87433SJohn Marino       break;
13544b87433SJohn Marino     case 7:
13644b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
13744b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
13844b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
13944b87433SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
14044b87433SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
14144b87433SJohn Marino                authors[5], authors[6]);
14244b87433SJohn Marino       break;
14344b87433SJohn Marino     case 8:
14444b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
14544b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
14644b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
14744b87433SJohn Marino       fprintf (stream, _("\
14844b87433SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
14944b87433SJohn Marino                 authors[0], authors[1], authors[2], authors[3], authors[4],
15044b87433SJohn Marino                 authors[5], authors[6], authors[7]);
15144b87433SJohn Marino       break;
15244b87433SJohn Marino     case 9:
15344b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
15444b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
15544b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
15644b87433SJohn Marino       fprintf (stream, _("\
15744b87433SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
15844b87433SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
15944b87433SJohn Marino                authors[5], authors[6], authors[7], authors[8]);
16044b87433SJohn Marino       break;
16144b87433SJohn Marino     default:
16244b87433SJohn Marino       /* 10 or more authors.  Use an abbreviation, since the human reader
16344b87433SJohn Marino          will probably not want to read the entire list anyway.  */
16444b87433SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
16544b87433SJohn Marino          You can use line breaks, estimating that each author name occupies
16644b87433SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
16744b87433SJohn Marino       fprintf (stream, _("\
16844b87433SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
16944b87433SJohn Marino                 authors[0], authors[1], authors[2], authors[3], authors[4],
17044b87433SJohn Marino                 authors[5], authors[6], authors[7], authors[8]);
17144b87433SJohn Marino       break;
17244b87433SJohn Marino     }
17344b87433SJohn Marino }
17444b87433SJohn Marino 
17544b87433SJohn Marino /* Display the --version information the standard way.  See the initial
17644b87433SJohn Marino    comment to this module, for more information.
17744b87433SJohn Marino 
17844b87433SJohn Marino    Author names are given in the NULL-terminated array AUTHORS. */
17944b87433SJohn Marino void
version_etc_ar(FILE * stream,const char * command_name,const char * package,const char * version,const char * const * authors)18044b87433SJohn Marino version_etc_ar (FILE *stream,
18144b87433SJohn Marino                 const char *command_name, const char *package,
18244b87433SJohn Marino                 const char *version, const char * const * authors)
18344b87433SJohn Marino {
18444b87433SJohn Marino   size_t n_authors;
18544b87433SJohn Marino 
18644b87433SJohn Marino   for (n_authors = 0; authors[n_authors]; n_authors++)
18744b87433SJohn Marino     ;
18844b87433SJohn Marino   version_etc_arn (stream, command_name, package, version, authors, n_authors);
18944b87433SJohn Marino }
19044b87433SJohn Marino 
19144b87433SJohn Marino /* Display the --version information the standard way.  See the initial
19244b87433SJohn Marino    comment to this module, for more information.
19344b87433SJohn Marino 
19444b87433SJohn Marino    Author names are given in the NULL-terminated va_list AUTHORS. */
19544b87433SJohn Marino void
version_etc_va(FILE * stream,const char * command_name,const char * package,const char * version,va_list authors)19644b87433SJohn Marino version_etc_va (FILE *stream,
19744b87433SJohn Marino                 const char *command_name, const char *package,
19844b87433SJohn Marino                 const char *version, va_list authors)
19944b87433SJohn Marino {
20044b87433SJohn Marino   size_t n_authors;
20144b87433SJohn Marino   const char *authtab[10];
20244b87433SJohn Marino 
20344b87433SJohn Marino   for (n_authors = 0;
20444b87433SJohn Marino        n_authors < 10
20544b87433SJohn Marino          && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
20644b87433SJohn Marino        n_authors++)
20744b87433SJohn Marino     ;
20844b87433SJohn Marino   version_etc_arn (stream, command_name, package, version,
20944b87433SJohn Marino                    authtab, n_authors);
21044b87433SJohn Marino }
21144b87433SJohn Marino 
21244b87433SJohn Marino 
21344b87433SJohn Marino /* Display the --version information the standard way.
21444b87433SJohn Marino 
21544b87433SJohn Marino    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
21644b87433SJohn Marino    the program.  The formats are therefore:
21744b87433SJohn Marino 
21844b87433SJohn Marino    PACKAGE VERSION
21944b87433SJohn Marino 
22044b87433SJohn Marino    or
22144b87433SJohn Marino 
22244b87433SJohn Marino    COMMAND_NAME (PACKAGE) VERSION.
22344b87433SJohn Marino 
22444b87433SJohn Marino    The authors names are passed as separate arguments, with an additional
225855caec6SPeter Avalos    NULL argument at the end.  */
226855caec6SPeter Avalos void
version_etc(FILE * stream,const char * command_name,const char * package,const char * version,...)227855caec6SPeter Avalos version_etc (FILE *stream,
228855caec6SPeter Avalos              const char *command_name, const char *package,
229855caec6SPeter Avalos              const char *version, /* const char *author1, ...*/ ...)
230855caec6SPeter Avalos {
231855caec6SPeter Avalos   va_list authors;
232855caec6SPeter Avalos 
233855caec6SPeter Avalos   va_start (authors, version);
234855caec6SPeter Avalos   version_etc_va (stream, command_name, package, version, authors);
23544b87433SJohn Marino   va_end (authors);
23644b87433SJohn Marino }
23744b87433SJohn Marino 
23844b87433SJohn Marino void
emit_bug_reporting_address(void)23944b87433SJohn Marino emit_bug_reporting_address (void)
24044b87433SJohn Marino {
24144b87433SJohn Marino   /* TRANSLATORS: The placeholder indicates the bug-reporting address
24244b87433SJohn Marino      for this package.  Please add _another line_ saying
24344b87433SJohn Marino      "Report translation bugs to <...>\n" with the address for translation
24444b87433SJohn Marino      bugs (typically your translation team's web or email address).  */
24544b87433SJohn Marino   printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
24644b87433SJohn Marino #ifdef PACKAGE_PACKAGER_BUG_REPORTS
24744b87433SJohn Marino   printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
24844b87433SJohn Marino           PACKAGE_PACKAGER_BUG_REPORTS);
24944b87433SJohn Marino #endif
25044b87433SJohn Marino #ifdef PACKAGE_URL
25144b87433SJohn Marino   printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
25244b87433SJohn Marino #else
253*6ea1f93eSDaniel Fojt   printf (_("%s home page: <https://www.gnu.org/software/%s/>\n"),
25444b87433SJohn Marino           PACKAGE_NAME, PACKAGE);
25544b87433SJohn Marino #endif
256*6ea1f93eSDaniel Fojt   fputs (_("General help using GNU software: <https://www.gnu.org/gethelp/>\n"),
25744b87433SJohn Marino          stdout);
258855caec6SPeter Avalos }
259