05bc3ad255a9024d45d11fe42bcac949ba86a04a
[gnulib.git] / lib / version-etc.c
1 /* Utility to help print --version output in a consistent format.
2    Copyright (C) 1999-2005 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 2, or (at your option)
7    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, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Jim Meyering. */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 /* Specification.  */
25 #include "version-etc.h"
26
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #if USE_UNLOCKED_IO
32 # include "unlocked-io.h"
33 #endif
34
35 #include "gettext.h"
36 #define _(msgid) gettext (msgid)
37
38 enum { COPYRIGHT_YEAR = 2005 };
39
40 /* Like version_etc, below, but with the NULL-terminated author list
41    provided via a variable of type va_list.  */
42 void
43 version_etc_va (FILE *stream,
44                 const char *command_name, const char *package,
45                 const char *version, va_list authors)
46 {
47   size_t n_authors;
48
49   /* Count the number of authors.  */
50   {
51     va_list tmp_authors;
52
53 #ifdef __va_copy
54     __va_copy (tmp_authors, authors);
55 #else
56     tmp_authors = authors;
57 #endif
58
59     n_authors = 0;
60     while (va_arg (tmp_authors, const char *) != NULL)
61       ++n_authors;
62   }
63
64   if (command_name)
65     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
66   else
67     fprintf (stream, "%s %s\n", package, version);
68
69   /* TRANSLATORS: Translate "(C)" to the copyright symbol
70      (C-in-a-circle), if this symbol is available in the user's
71      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
72   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
73
74   fputs (_("\
75 \n\
76 This is free software.  You may redistribute copies of it under the terms of\n\
77 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n\
78 There is NO WARRANTY, to the extent permitted by law.\n\
79 \n\
80 "),
81          stream);
82
83   switch (n_authors)
84     {
85     case 0:
86       /* The caller must provide at least one author name.  */
87       abort ();
88     case 1:
89       /* TRANSLATORS: %s denotes an author name.  */
90       vfprintf (stream, _("Written by %s.\n"), authors);
91       break;
92     case 2:
93       /* TRANSLATORS: Each %s denotes an author name.  */
94       vfprintf (stream, _("Written by %s and %s.\n"), authors);
95       break;
96     case 3:
97       /* TRANSLATORS: Each %s denotes an author name.  */
98       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
99       break;
100     case 4:
101       /* TRANSLATORS: Each %s denotes an author name.
102          You can use line breaks, estimating that each author name occupies
103          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
104       vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
105       break;
106     case 5:
107       /* TRANSLATORS: Each %s denotes an author name.
108          You can use line breaks, estimating that each author name occupies
109          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
110       vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
111       break;
112     case 6:
113       /* TRANSLATORS: Each %s denotes an author name.
114          You can use line breaks, estimating that each author name occupies
115          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
116       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
117                 authors);
118       break;
119     case 7:
120       /* TRANSLATORS: Each %s denotes an author name.
121          You can use line breaks, estimating that each author name occupies
122          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
123       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
124                 authors);
125       break;
126     case 8:
127       /* TRANSLATORS: Each %s denotes an author name.
128          You can use line breaks, estimating that each author name occupies
129          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
130       vfprintf (stream, _("\
131 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
132                 authors);
133       break;
134     case 9:
135       /* TRANSLATORS: Each %s denotes an author name.
136          You can use line breaks, estimating that each author name occupies
137          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
138       vfprintf (stream, _("\
139 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
140                 authors);
141       break;
142     default:
143       /* 10 or more authors.  Use an abbreviation, since the human reader
144          will probably not want to read the entire list anyway.  */
145       /* TRANSLATORS: Each %s denotes an author name.
146          You can use line breaks, estimating that each author name occupies
147          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
148       vfprintf (stream, _("\
149 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
150                 authors);
151       break;
152     }
153   va_end (authors);
154 }
155
156
157 /* Display the --version information the standard way.
158
159    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
160    the program.  The formats are therefore:
161
162    PACKAGE VERSION
163
164    or
165
166    COMMAND_NAME (PACKAGE) VERSION.
167
168    The author names are passed as separate arguments, with an additional
169    NULL argument at the end.  */
170 void
171 version_etc (FILE *stream,
172              const char *command_name, const char *package,
173              const char *version, /* const char *author1, ...*/ ...)
174 {
175   va_list authors;
176
177   va_start (authors, version);
178   version_etc_va (stream, command_name, package, version, authors);
179 }