1/* Utility to help print --version output in a consistent format.
2   Copyright (C) 1999-2007 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#include <config.h>
21
22/* Specification.  */
23#include "version-etc.h"
24
25#include <stdarg.h>
26#include <stdio.h>
27#include <stdlib.h>
28
29#if USE_UNLOCKED_IO
30# include "unlocked-io.h"
31#endif
32
33#include "gettext.h"
34#define _(msgid) gettext (msgid)
35
36enum { COPYRIGHT_YEAR = 2007 };
37
38/* Like version_etc, below, but with the NULL-terminated author list
39   provided via a variable of type va_list.  */
40void
41version_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    va_copy (tmp_authors, authors);
52
53    n_authors = 0;
54    while (va_arg (tmp_authors, const char *) != NULL)
55      ++n_authors;
56  }
57
58  if (command_name)
59    fprintf (stream, "%s (%s) %s\n", command_name, package, version);
60  else
61    fprintf (stream, "%s %s\n", package, version);
62
63  /* TRANSLATORS: Translate "(C)" to the copyright symbol
64     (C-in-a-circle), if this symbol is available in the user's
65     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
66  fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
67
68  fputs (_("\
69\n\
70License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n\
71This is free software: you are free to change and redistribute it.\n\
72There is NO WARRANTY, to the extent permitted by law.\n\
73\n\
74"),
75	 stream);
76
77  fputs (_("Modified to support extended attributes.\n"), 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, _("\
127Written 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, _("\
135Written 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, _("\
145Written 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.  */
166void
167version_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}
176