*** empty log message ***
[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 #if 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 /* Like version_etc, below, but with the NULL-terminated author list
39    provided via a variable of type va_list.  */
40 void
41 version_etc_va (FILE *stream,
42                 const char *command_name, const char *package,
43                 const char *version, va_list authors)
44 {
45   size_t n_authors;
46
47   /* Count the number of authors.  */
48   {
49     va_list tmp_authors;
50
51 #ifdef __va_copy
52     __va_copy (tmp_authors, authors);
53 #else
54     tmp_authors = authors;
55 #endif
56
57     n_authors = 0;
58     while (va_arg (tmp_authors, const char *) != NULL)
59       ++n_authors;
60   }
61
62   if (command_name)
63     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
64   else
65     fprintf (stream, "%s %s\n", package, version);
66
67   switch (n_authors)
68     {
69     case 0:
70       /* The caller must provide at least one author name.  */
71       abort ();
72     case 1:
73       /* TRANSLATORS: %s denotes an author name.  */
74       vfprintf (stream, _("Written by %s.\n"), authors);
75       break;
76     case 2:
77       /* TRANSLATORS: Each %s denotes an author name.  */
78       vfprintf (stream, _("Written by %s and %s.\n"), authors);
79       break;
80     case 3:
81       /* TRANSLATORS: Each %s denotes an author name.  */
82       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
83       break;
84     case 4:
85       /* TRANSLATORS: Each %s denotes an author name.
86          You can use line breaks, estimating that each author name occupies
87          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
88       vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
89       break;
90     case 5:
91       /* TRANSLATORS: Each %s denotes an author name.
92          You can use line breaks, estimating that each author name occupies
93          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
94       vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
95       break;
96     case 6:
97       /* TRANSLATORS: Each %s denotes an author name.
98          You can use line breaks, estimating that each author name occupies
99          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
100       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
101                 authors);
102       break;
103     case 7:
104       /* TRANSLATORS: Each %s denotes an author name.
105          You can use line breaks, estimating that each author name occupies
106          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
107       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
108                 authors);
109       break;
110     case 8:
111       /* TRANSLATORS: Each %s denotes an author name.
112          You can use line breaks, estimating that each author name occupies
113          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
114       vfprintf (stream, _("\
115 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
116                 authors);
117       break;
118     case 9:
119       /* TRANSLATORS: Each %s denotes an author name.
120          You can use line breaks, estimating that each author name occupies
121          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
122       vfprintf (stream, _("\
123 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
124                 authors);
125       break;
126     default:
127       /* 10 or more authors.  Use an abbreviation, since the human reader
128          will probably not want to read the entire list anyway.  */
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,\n%s, %s, and others.\n"),
134                 authors);
135       break;
136     }
137   va_end (authors);
138   putc ('\n', stream);
139
140   fputs (version_etc_copyright, stream);
141   putc ('\n', stream);
142
143   fputs (_("\
144 This is free software; see the source for copying conditions.  There is NO\n\
145 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
146          stream);
147 }
148
149
150 /* Display the --version information the standard way.
151
152    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
153    the program.  The formats are therefore:
154
155    PACKAGE VERSION
156
157    or
158
159    COMMAND_NAME (PACKAGE) VERSION.
160
161    The author names are passed as separate arguments, with an additional
162    NULL argument at the end.  */
163 void
164 version_etc (FILE *stream,
165              const char *command_name, const char *package,
166              const char *version, /* const char *author1, ...*/ ...)
167 {
168   va_list authors;
169
170   va_start (authors, version);
171   version_etc_va (stream, command_name, package, version, authors);
172 }