vendor/diffutils: upgrade from 3.3 to 3.7
[dragonfly.git] / contrib / diffutils / lib / version-etc.c
1 /* Print --version and bug-reporting information in a consistent format.
2    Copyright (C) 1999-2018 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16
17 /* Written by Jim Meyering. */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "version-etc.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #if USE_UNLOCKED_IO
28 # include "unlocked-io.h"
29 #endif
30
31 #include "gettext.h"
32 #define _(msgid) gettext (msgid)
33
34 /* If you use AM_INIT_AUTOMAKE's no-define option,
35    PACKAGE is not defined.  Use PACKAGE_TARNAME instead.  */
36 #if ! defined PACKAGE && defined PACKAGE_TARNAME
37 # define PACKAGE PACKAGE_TARNAME
38 #endif
39
40 enum { COPYRIGHT_YEAR = 2018 };
41
42 /* The three functions below display the --version information the
43    standard way.
44
45    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
46    the program.  The formats are therefore:
47
48    PACKAGE VERSION
49
50    or
51
52    COMMAND_NAME (PACKAGE) VERSION.
53
54    The functions differ in the way they are passed author names. */
55
56 /* Display the --version information the standard way.
57
58    Author names are given in the array AUTHORS. N_AUTHORS is the
59    number of elements in the array. */
60 void
61 version_etc_arn (FILE *stream,
62                  const char *command_name, const char *package,
63                  const char *version,
64                  const char * const * authors, size_t n_authors)
65 {
66   if (command_name)
67     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
68   else
69     fprintf (stream, "%s %s\n", package, version);
70
71 #ifdef PACKAGE_PACKAGER
72 # ifdef PACKAGE_PACKAGER_VERSION
73   fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
74            PACKAGE_PACKAGER_VERSION);
75 # else
76   fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
77 # endif
78 #endif
79
80   /* TRANSLATORS: Translate "(C)" to the copyright symbol
81      (C-in-a-circle), if this symbol is available in the user's
82      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
83   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
84
85   fputs (_("\
86 \n\
87 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n\
88 This is free software: you are free to change and redistribute it.\n\
89 There is NO WARRANTY, to the extent permitted by law.\n\
90 \n\
91 "),
92          stream);
93
94   switch (n_authors)
95     {
96     case 0:
97       /* No authors are given.  The caller should output authorship
98          info after calling this function.  */
99       break;
100     case 1:
101       /* TRANSLATORS: %s denotes an author name.  */
102       fprintf (stream, _("Written by %s.\n"), authors[0]);
103       break;
104     case 2:
105       /* TRANSLATORS: Each %s denotes an author name.  */
106       fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
107       break;
108     case 3:
109       /* TRANSLATORS: Each %s denotes an author name.  */
110       fprintf (stream, _("Written by %s, %s, and %s.\n"),
111                authors[0], authors[1], authors[2]);
112       break;
113     case 4:
114       /* TRANSLATORS: Each %s denotes an author name.
115          You can use line breaks, estimating that each author name occupies
116          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
117       fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
118                authors[0], authors[1], authors[2], authors[3]);
119       break;
120     case 5:
121       /* TRANSLATORS: Each %s denotes an author name.
122          You can use line breaks, estimating that each author name occupies
123          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
124       fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
125                authors[0], authors[1], authors[2], authors[3], authors[4]);
126       break;
127     case 6:
128       /* TRANSLATORS: Each %s denotes an author name.
129          You can use line breaks, estimating that each author name occupies
130          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
131       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
132                authors[0], authors[1], authors[2], authors[3], authors[4],
133                authors[5]);
134       break;
135     case 7:
136       /* TRANSLATORS: Each %s denotes an author name.
137          You can use line breaks, estimating that each author name occupies
138          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
139       fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
140                authors[0], authors[1], authors[2], authors[3], authors[4],
141                authors[5], authors[6]);
142       break;
143     case 8:
144       /* TRANSLATORS: Each %s denotes an author name.
145          You can use line breaks, estimating that each author name occupies
146          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
147       fprintf (stream, _("\
148 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
149                 authors[0], authors[1], authors[2], authors[3], authors[4],
150                 authors[5], authors[6], authors[7]);
151       break;
152     case 9:
153       /* TRANSLATORS: Each %s denotes an author name.
154          You can use line breaks, estimating that each author name occupies
155          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
156       fprintf (stream, _("\
157 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
158                authors[0], authors[1], authors[2], authors[3], authors[4],
159                authors[5], authors[6], authors[7], authors[8]);
160       break;
161     default:
162       /* 10 or more authors.  Use an abbreviation, since the human reader
163          will probably not want to read the entire list anyway.  */
164       /* TRANSLATORS: Each %s denotes an author name.
165          You can use line breaks, estimating that each author name occupies
166          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
167       fprintf (stream, _("\
168 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
169                 authors[0], authors[1], authors[2], authors[3], authors[4],
170                 authors[5], authors[6], authors[7], authors[8]);
171       break;
172     }
173 }
174
175 /* Display the --version information the standard way.  See the initial
176    comment to this module, for more information.
177
178    Author names are given in the NULL-terminated array AUTHORS. */
179 void
180 version_etc_ar (FILE *stream,
181                 const char *command_name, const char *package,
182                 const char *version, const char * const * authors)
183 {
184   size_t n_authors;
185
186   for (n_authors = 0; authors[n_authors]; n_authors++)
187     ;
188   version_etc_arn (stream, command_name, package, version, authors, n_authors);
189 }
190
191 /* Display the --version information the standard way.  See the initial
192    comment to this module, for more information.
193
194    Author names are given in the NULL-terminated va_list AUTHORS. */
195 void
196 version_etc_va (FILE *stream,
197                 const char *command_name, const char *package,
198                 const char *version, va_list authors)
199 {
200   size_t n_authors;
201   const char *authtab[10];
202
203   for (n_authors = 0;
204        n_authors < 10
205          && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
206        n_authors++)
207     ;
208   version_etc_arn (stream, command_name, package, version,
209                    authtab, n_authors);
210 }
211
212
213 /* Display the --version information the standard way.
214
215    If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
216    the program.  The formats are therefore:
217
218    PACKAGE VERSION
219
220    or
221
222    COMMAND_NAME (PACKAGE) VERSION.
223
224    The authors names are passed as separate arguments, with an additional
225    NULL argument at the end.  */
226 void
227 version_etc (FILE *stream,
228              const char *command_name, const char *package,
229              const char *version, /* const char *author1, ...*/ ...)
230 {
231   va_list authors;
232
233   va_start (authors, version);
234   version_etc_va (stream, command_name, package, version, authors);
235   va_end (authors);
236 }
237
238 void
239 emit_bug_reporting_address (void)
240 {
241   /* TRANSLATORS: The placeholder indicates the bug-reporting address
242      for this package.  Please add _another line_ saying
243      "Report translation bugs to <...>\n" with the address for translation
244      bugs (typically your translation team's web or email address).  */
245   printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
246 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
247   printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
248           PACKAGE_PACKAGER_BUG_REPORTS);
249 #endif
250 #ifdef PACKAGE_URL
251   printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
252 #else
253   printf (_("%s home page: <https://www.gnu.org/software/%s/>\n"),
254           PACKAGE_NAME, PACKAGE);
255 #endif
256   fputs (_("General help using GNU software: <https://www.gnu.org/gethelp/>\n"),
257          stdout);
258 }