xref: /dragonfly/contrib/grep/lib/version-etc.c (revision 09d4459f)
195b7b453SJohn Marino /* Print --version and bug-reporting information in a consistent format.
2*09d4459fSDaniel Fojt    Copyright (C) 1999-2020 Free Software Foundation, Inc.
395b7b453SJohn Marino 
495b7b453SJohn Marino    This program is free software: you can redistribute it and/or modify
595b7b453SJohn Marino    it under the terms of the GNU General Public License as published by
695b7b453SJohn Marino    the Free Software Foundation; either version 3 of the License, or
795b7b453SJohn Marino    (at your option) any later version.
895b7b453SJohn Marino 
995b7b453SJohn Marino    This program is distributed in the hope that it will be useful,
1095b7b453SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
1195b7b453SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1295b7b453SJohn Marino    GNU General Public License for more details.
1395b7b453SJohn Marino 
1495b7b453SJohn Marino    You should have received a copy of the GNU General Public License
15*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
1695b7b453SJohn Marino 
1795b7b453SJohn Marino /* Written by Jim Meyering. */
1895b7b453SJohn Marino 
1995b7b453SJohn Marino #include <config.h>
2095b7b453SJohn Marino 
2195b7b453SJohn Marino /* Specification.  */
2295b7b453SJohn Marino #include "version-etc.h"
2395b7b453SJohn Marino 
2495b7b453SJohn Marino #include <stdarg.h>
2595b7b453SJohn Marino #include <stdio.h>
2695b7b453SJohn Marino 
2795b7b453SJohn Marino #if USE_UNLOCKED_IO
2895b7b453SJohn Marino # include "unlocked-io.h"
2995b7b453SJohn Marino #endif
3095b7b453SJohn Marino 
3195b7b453SJohn Marino #include "gettext.h"
3295b7b453SJohn Marino #define _(msgid) gettext (msgid)
3395b7b453SJohn Marino 
3495b7b453SJohn Marino /* If you use AM_INIT_AUTOMAKE's no-define option,
3595b7b453SJohn Marino    PACKAGE is not defined.  Use PACKAGE_TARNAME instead.  */
3695b7b453SJohn Marino #if ! defined PACKAGE && defined PACKAGE_TARNAME
3795b7b453SJohn Marino # define PACKAGE PACKAGE_TARNAME
3895b7b453SJohn Marino #endif
3995b7b453SJohn Marino 
40*09d4459fSDaniel Fojt enum { COPYRIGHT_YEAR = 2020 };
4195b7b453SJohn Marino 
4295b7b453SJohn Marino /* The three functions below display the --version information the
4395b7b453SJohn Marino    standard way.
4495b7b453SJohn Marino 
4595b7b453SJohn Marino    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
4695b7b453SJohn Marino    the program.  The formats are therefore:
4795b7b453SJohn Marino 
4895b7b453SJohn Marino    PACKAGE VERSION
4995b7b453SJohn Marino 
5095b7b453SJohn Marino    or
5195b7b453SJohn Marino 
5295b7b453SJohn Marino    COMMAND_NAME (PACKAGE) VERSION.
5395b7b453SJohn Marino 
5495b7b453SJohn Marino    The functions differ in the way they are passed author names. */
5595b7b453SJohn Marino 
5695b7b453SJohn Marino /* Display the --version information the standard way.
5795b7b453SJohn Marino 
5895b7b453SJohn Marino    Author names are given in the array AUTHORS. N_AUTHORS is the
5995b7b453SJohn Marino    number of elements in the array. */
6095b7b453SJohn 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)6195b7b453SJohn Marino version_etc_arn (FILE *stream,
6295b7b453SJohn Marino                  const char *command_name, const char *package,
6395b7b453SJohn Marino                  const char *version,
6495b7b453SJohn Marino                  const char * const * authors, size_t n_authors)
6595b7b453SJohn Marino {
6695b7b453SJohn Marino   if (command_name)
6795b7b453SJohn Marino     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
6895b7b453SJohn Marino   else
6995b7b453SJohn Marino     fprintf (stream, "%s %s\n", package, version);
7095b7b453SJohn Marino 
7195b7b453SJohn Marino #ifdef PACKAGE_PACKAGER
7295b7b453SJohn Marino # ifdef PACKAGE_PACKAGER_VERSION
7395b7b453SJohn Marino   fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
7495b7b453SJohn Marino            PACKAGE_PACKAGER_VERSION);
7595b7b453SJohn Marino # else
7695b7b453SJohn Marino   fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
7795b7b453SJohn Marino # endif
7895b7b453SJohn Marino #endif
7995b7b453SJohn Marino 
8095b7b453SJohn Marino   /* TRANSLATORS: Translate "(C)" to the copyright symbol
8195b7b453SJohn Marino      (C-in-a-circle), if this symbol is available in the user's
8295b7b453SJohn Marino      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
8395b7b453SJohn Marino   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
8495b7b453SJohn Marino 
85*09d4459fSDaniel Fojt   fputs ("\n", stream);
86*09d4459fSDaniel Fojt 
87*09d4459fSDaniel Fojt   /* TRANSLATORS: The %s placeholder is the web address of the GPL license.  */
88*09d4459fSDaniel Fojt   fprintf (stream, _("\
89*09d4459fSDaniel Fojt License GPLv3+: GNU GPL version 3 or later <%s>.\n\
9095b7b453SJohn Marino This is free software: you are free to change and redistribute it.\n\
9195b7b453SJohn Marino There is NO WARRANTY, to the extent permitted by law.\n\
9295b7b453SJohn Marino "),
93*09d4459fSDaniel Fojt            "https://gnu.org/licenses/gpl.html");
94*09d4459fSDaniel Fojt 
95*09d4459fSDaniel Fojt   fputs ("\n", stream);
9695b7b453SJohn Marino 
9795b7b453SJohn Marino   switch (n_authors)
9895b7b453SJohn Marino     {
9995b7b453SJohn Marino     case 0:
100*09d4459fSDaniel Fojt       /* No authors are given.  The caller should output authorship
101*09d4459fSDaniel Fojt          info after calling this function.  */
102*09d4459fSDaniel Fojt       break;
10395b7b453SJohn Marino     case 1:
10495b7b453SJohn Marino       /* TRANSLATORS: %s denotes an author name.  */
10595b7b453SJohn Marino       fprintf (stream, _("Written by %s.\n"), authors[0]);
10695b7b453SJohn Marino       break;
10795b7b453SJohn Marino     case 2:
10895b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.  */
10995b7b453SJohn Marino       fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
11095b7b453SJohn Marino       break;
11195b7b453SJohn Marino     case 3:
11295b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.  */
11395b7b453SJohn Marino       fprintf (stream, _("Written by %s, %s, and %s.\n"),
11495b7b453SJohn Marino                authors[0], authors[1], authors[2]);
11595b7b453SJohn Marino       break;
11695b7b453SJohn Marino     case 4:
11795b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
11895b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
11995b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
12095b7b453SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
12195b7b453SJohn Marino                authors[0], authors[1], authors[2], authors[3]);
12295b7b453SJohn Marino       break;
12395b7b453SJohn Marino     case 5:
12495b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
12595b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
12695b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
12795b7b453SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
12895b7b453SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4]);
12995b7b453SJohn Marino       break;
13095b7b453SJohn Marino     case 6:
13195b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
13295b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
13395b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
13495b7b453SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
13595b7b453SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
13695b7b453SJohn Marino                authors[5]);
13795b7b453SJohn Marino       break;
13895b7b453SJohn Marino     case 7:
13995b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
14095b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
14195b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
14295b7b453SJohn Marino       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
14395b7b453SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
14495b7b453SJohn Marino                authors[5], authors[6]);
14595b7b453SJohn Marino       break;
14695b7b453SJohn Marino     case 8:
14795b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
14895b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
14995b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
15095b7b453SJohn Marino       fprintf (stream, _("\
15195b7b453SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
15295b7b453SJohn Marino                 authors[0], authors[1], authors[2], authors[3], authors[4],
15395b7b453SJohn Marino                 authors[5], authors[6], authors[7]);
15495b7b453SJohn Marino       break;
15595b7b453SJohn Marino     case 9:
15695b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
15795b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
15895b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
15995b7b453SJohn Marino       fprintf (stream, _("\
16095b7b453SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
16195b7b453SJohn Marino                authors[0], authors[1], authors[2], authors[3], authors[4],
16295b7b453SJohn Marino                authors[5], authors[6], authors[7], authors[8]);
16395b7b453SJohn Marino       break;
16495b7b453SJohn Marino     default:
16595b7b453SJohn Marino       /* 10 or more authors.  Use an abbreviation, since the human reader
16695b7b453SJohn Marino          will probably not want to read the entire list anyway.  */
16795b7b453SJohn Marino       /* TRANSLATORS: Each %s denotes an author name.
16895b7b453SJohn Marino          You can use line breaks, estimating that each author name occupies
16995b7b453SJohn Marino          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
17095b7b453SJohn Marino       fprintf (stream, _("\
17195b7b453SJohn Marino Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
17295b7b453SJohn Marino                 authors[0], authors[1], authors[2], authors[3], authors[4],
17395b7b453SJohn Marino                 authors[5], authors[6], authors[7], authors[8]);
17495b7b453SJohn Marino       break;
17595b7b453SJohn Marino     }
17695b7b453SJohn Marino }
17795b7b453SJohn Marino 
17895b7b453SJohn Marino /* Display the --version information the standard way.  See the initial
17995b7b453SJohn Marino    comment to this module, for more information.
18095b7b453SJohn Marino 
18195b7b453SJohn Marino    Author names are given in the NULL-terminated array AUTHORS. */
18295b7b453SJohn Marino void
version_etc_ar(FILE * stream,const char * command_name,const char * package,const char * version,const char * const * authors)18395b7b453SJohn Marino version_etc_ar (FILE *stream,
18495b7b453SJohn Marino                 const char *command_name, const char *package,
18595b7b453SJohn Marino                 const char *version, const char * const * authors)
18695b7b453SJohn Marino {
18795b7b453SJohn Marino   size_t n_authors;
18895b7b453SJohn Marino 
18995b7b453SJohn Marino   for (n_authors = 0; authors[n_authors]; n_authors++)
19095b7b453SJohn Marino     ;
19195b7b453SJohn Marino   version_etc_arn (stream, command_name, package, version, authors, n_authors);
19295b7b453SJohn Marino }
19395b7b453SJohn Marino 
19495b7b453SJohn Marino /* Display the --version information the standard way.  See the initial
19595b7b453SJohn Marino    comment to this module, for more information.
19695b7b453SJohn Marino 
19795b7b453SJohn Marino    Author names are given in the NULL-terminated va_list AUTHORS. */
19895b7b453SJohn Marino void
version_etc_va(FILE * stream,const char * command_name,const char * package,const char * version,va_list authors)19995b7b453SJohn Marino version_etc_va (FILE *stream,
20095b7b453SJohn Marino                 const char *command_name, const char *package,
20195b7b453SJohn Marino                 const char *version, va_list authors)
20295b7b453SJohn Marino {
20395b7b453SJohn Marino   size_t n_authors;
20495b7b453SJohn Marino   const char *authtab[10];
20595b7b453SJohn Marino 
20695b7b453SJohn Marino   for (n_authors = 0;
20795b7b453SJohn Marino        n_authors < 10
20895b7b453SJohn Marino          && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
20995b7b453SJohn Marino        n_authors++)
21095b7b453SJohn Marino     ;
21195b7b453SJohn Marino   version_etc_arn (stream, command_name, package, version,
21295b7b453SJohn Marino                    authtab, n_authors);
21395b7b453SJohn Marino }
21495b7b453SJohn Marino 
21595b7b453SJohn Marino 
21695b7b453SJohn Marino /* Display the --version information the standard way.
21795b7b453SJohn Marino 
21895b7b453SJohn Marino    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
21995b7b453SJohn Marino    the program.  The formats are therefore:
22095b7b453SJohn Marino 
22195b7b453SJohn Marino    PACKAGE VERSION
22295b7b453SJohn Marino 
22395b7b453SJohn Marino    or
22495b7b453SJohn Marino 
22595b7b453SJohn Marino    COMMAND_NAME (PACKAGE) VERSION.
22695b7b453SJohn Marino 
22795b7b453SJohn Marino    The authors names are passed as separate arguments, with an additional
22895b7b453SJohn Marino    NULL argument at the end.  */
22995b7b453SJohn Marino void
version_etc(FILE * stream,const char * command_name,const char * package,const char * version,...)23095b7b453SJohn Marino version_etc (FILE *stream,
23195b7b453SJohn Marino              const char *command_name, const char *package,
23295b7b453SJohn Marino              const char *version, /* const char *author1, ...*/ ...)
23395b7b453SJohn Marino {
23495b7b453SJohn Marino   va_list authors;
23595b7b453SJohn Marino 
23695b7b453SJohn Marino   va_start (authors, version);
23795b7b453SJohn Marino   version_etc_va (stream, command_name, package, version, authors);
23895b7b453SJohn Marino   va_end (authors);
23995b7b453SJohn Marino }
24095b7b453SJohn Marino 
24195b7b453SJohn Marino void
emit_bug_reporting_address(void)24295b7b453SJohn Marino emit_bug_reporting_address (void)
24395b7b453SJohn Marino {
244*09d4459fSDaniel Fojt   fputs ("\n", stdout);
24595b7b453SJohn Marino   /* TRANSLATORS: The placeholder indicates the bug-reporting address
24695b7b453SJohn Marino      for this package.  Please add _another line_ saying
24795b7b453SJohn Marino      "Report translation bugs to <...>\n" with the address for translation
24895b7b453SJohn Marino      bugs (typically your translation team's web or email address).  */
249*09d4459fSDaniel Fojt   printf (_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
25095b7b453SJohn Marino #ifdef PACKAGE_PACKAGER_BUG_REPORTS
25195b7b453SJohn Marino   printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
25295b7b453SJohn Marino           PACKAGE_PACKAGER_BUG_REPORTS);
25395b7b453SJohn Marino #endif
25495b7b453SJohn Marino #ifdef PACKAGE_URL
25595b7b453SJohn Marino   printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
25695b7b453SJohn Marino #else
257*09d4459fSDaniel Fojt   printf (_("%s home page: <%s>\n"),
258*09d4459fSDaniel Fojt           PACKAGE_NAME, "https://www.gnu.org/software/" PACKAGE "/");
25995b7b453SJohn Marino #endif
260*09d4459fSDaniel Fojt   printf (_("General help using GNU software: <%s>\n"),
261*09d4459fSDaniel Fojt           "https://www.gnu.org/gethelp/");
26295b7b453SJohn Marino }
263