Use the stdarg module.
[gnulib.git] / lib / version-etc.c
1 /* Utility to help print --version output in a consistent format.
2    Copyright (C) 1999-2006 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 = 2006 };
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     va_copy (tmp_authors, authors);
54
55     n_authors = 0;
56     while (va_arg (tmp_authors, const char *) != NULL)
57       ++n_authors;
58   }
59
60   if (command_name)
61     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
62   else
63     fprintf (stream, "%s %s\n", package, version);
64
65   /* TRANSLATORS: Translate "(C)" to the copyright symbol
66      (C-in-a-circle), if this symbol is available in the user's
67      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
68   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
69
70   fputs (_("\
71 \n\
72 This is free software.  You may redistribute copies of it under the terms of\n\
73 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n\
74 There is NO WARRANTY, to the extent permitted by law.\n\
75 \n\
76 "),
77          stream);
78
79   switch (n_authors)
80     {
81     case 0:
82       /* The caller must provide at least one author name.  */
83       abort ();
84     case 1:
85       /* TRANSLATORS: %s denotes an author name.  */
86       vfprintf (stream, _("Written by %s.\n"), authors);
87       break;
88     case 2:
89       /* TRANSLATORS: Each %s denotes an author name.  */
90       vfprintf (stream, _("Written by %s and %s.\n"), authors);
91       break;
92     case 3:
93       /* TRANSLATORS: Each %s denotes an author name.  */
94       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
95       break;
96     case 4:
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,\nand %s.\n"), authors);
101       break;
102     case 5:
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,\n%s, and %s.\n"), authors);
107       break;
108     case 6:
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, %s, and %s.\n"),
113                 authors);
114       break;
115     case 7:
116       /* TRANSLATORS: Each %s denotes an author name.
117          You can use line breaks, estimating that each author name occupies
118          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
119       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
120                 authors);
121       break;
122     case 8:
123       /* TRANSLATORS: Each %s denotes an author name.
124          You can use line breaks, estimating that each author name occupies
125          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
126       vfprintf (stream, _("\
127 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
128                 authors);
129       break;
130     case 9:
131       /* TRANSLATORS: Each %s denotes an author name.
132          You can use line breaks, estimating that each author name occupies
133          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
134       vfprintf (stream, _("\
135 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
136                 authors);
137       break;
138     default:
139       /* 10 or more authors.  Use an abbreviation, since the human reader
140          will probably not want to read the entire list anyway.  */
141       /* TRANSLATORS: Each %s denotes an author name.
142          You can use line breaks, estimating that each author name occupies
143          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
144       vfprintf (stream, _("\
145 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
146                 authors);
147       break;
148     }
149   va_end (authors);
150 }
151
152
153 /* Display the --version information the standard way.
154
155    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
156    the program.  The formats are therefore:
157
158    PACKAGE VERSION
159
160    or
161
162    COMMAND_NAME (PACKAGE) VERSION.
163
164    The author names are passed as separate arguments, with an additional
165    NULL argument at the end.  */
166 void
167 version_etc (FILE *stream,
168              const char *command_name, const char *package,
169              const char *version, /* const char *author1, ...*/ ...)
170 {
171   va_list authors;
172
173   va_start (authors, version);
174   version_etc_va (stream, command_name, package, version, authors);
175 }