c3b028926b8cd76130016bc8e217f509926e8c71
[gnulib.git] / lib / version-etc.c
1 /* Print --version and bug-reporting information in a consistent format.
2    Copyright (C) 1999-2009 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 <http://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 #include <stdlib.h>
27
28 #if USE_UNLOCKED_IO
29 # include "unlocked-io.h"
30 #endif
31
32 #include "gettext.h"
33 #define _(msgid) gettext (msgid)
34
35 enum { COPYRIGHT_YEAR = 2009 };
36
37 /* Like version_etc, below, but with the NULL-terminated author list
38    provided via a variable of type va_list.  */
39 void
40 version_etc_va (FILE *stream,
41                 const char *command_name, const char *package,
42                 const char *version, va_list authors)
43 {
44   size_t n_authors;
45
46   /* Count the number of authors.  */
47   {
48     va_list tmp_authors;
49
50     va_copy (tmp_authors, authors);
51
52     n_authors = 0;
53     while (va_arg (tmp_authors, const char *) != NULL)
54       ++n_authors;
55   }
56
57   if (command_name)
58     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
59   else
60     fprintf (stream, "%s %s\n", package, version);
61
62 #ifdef PACKAGE_PACKAGER
63 # ifdef PACKAGE_PACKAGER_VERSION
64   fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
65            PACKAGE_PACKAGER_VERSION);
66 # else
67   fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
68 # endif
69 #endif
70
71   /* TRANSLATORS: Translate "(C)" to the copyright symbol
72      (C-in-a-circle), if this symbol is available in the user's
73      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
74   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
75
76   fputs (_("\
77 \n\
78 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
79 This is free software: you are free to change and redistribute it.\n\
80 There is NO WARRANTY, to the extent permitted by law.\n\
81 \n\
82 "),
83          stream);
84
85   switch (n_authors)
86     {
87     case 0:
88       /* The caller must provide at least one author name.  */
89       abort ();
90     case 1:
91       /* TRANSLATORS: %s denotes an author name.  */
92       vfprintf (stream, _("Written by %s.\n"), authors);
93       break;
94     case 2:
95       /* TRANSLATORS: Each %s denotes an author name.  */
96       vfprintf (stream, _("Written by %s and %s.\n"), authors);
97       break;
98     case 3:
99       /* TRANSLATORS: Each %s denotes an author name.  */
100       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
101       break;
102     case 4:
103       /* TRANSLATORS: Each %s denotes an author name.
104          You can use line breaks, estimating that each author name occupies
105          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
106       vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
107       break;
108     case 5:
109       /* TRANSLATORS: Each %s denotes an author name.
110          You can use line breaks, estimating that each author name occupies
111          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
112       vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
113       break;
114     case 6:
115       /* TRANSLATORS: Each %s denotes an author name.
116          You can use line breaks, estimating that each author name occupies
117          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
118       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
119                 authors);
120       break;
121     case 7:
122       /* TRANSLATORS: Each %s denotes an author name.
123          You can use line breaks, estimating that each author name occupies
124          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
125       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
126                 authors);
127       break;
128     case 8:
129       /* TRANSLATORS: Each %s denotes an author name.
130          You can use line breaks, estimating that each author name occupies
131          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
132       vfprintf (stream, _("\
133 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
134                 authors);
135       break;
136     case 9:
137       /* TRANSLATORS: Each %s denotes an author name.
138          You can use line breaks, estimating that each author name occupies
139          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
140       vfprintf (stream, _("\
141 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
142                 authors);
143       break;
144     default:
145       /* 10 or more authors.  Use an abbreviation, since the human reader
146          will probably not want to read the entire list anyway.  */
147       /* TRANSLATORS: Each %s denotes an author name.
148          You can use line breaks, estimating that each author name occupies
149          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
150       vfprintf (stream, _("\
151 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
152                 authors);
153       break;
154     }
155   va_end (authors);
156 }
157
158
159 /* Display the --version information the standard way.
160
161    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
162    the program.  The formats are therefore:
163
164    PACKAGE VERSION
165
166    or
167
168    COMMAND_NAME (PACKAGE) VERSION.
169
170    The author names are passed as separate arguments, with an additional
171    NULL argument at the end.  */
172 void
173 version_etc (FILE *stream,
174              const char *command_name, const char *package,
175              const char *version, /* const char *author1, ...*/ ...)
176 {
177   va_list authors;
178
179   va_start (authors, version);
180   version_etc_va (stream, command_name, package, version, authors);
181 }
182
183 void
184 emit_bug_reporting_address (void)
185 {
186   /* TRANSLATORS: The placeholder indicates the bug-reporting address
187      for this package.  Please add _another line_ saying
188      "Report translation bugs to <...>\n" with the address for translation
189      bugs (typically your translation team's web or email address).  */
190   printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
191 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
192   printf (_("Report %s bugs to <%s>.\n"), PACKAGE_PACKAGER,
193           PACKAGE_PACKAGER_BUG_REPORTS);
194 #endif
195   printf (_("%s home page: <http://www.gnu.org/software/%s/>.\n"),
196           PACKAGE_NAME, PACKAGE);
197   fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>.\n"),
198          stdout);
199 }