1170754Sdelphij/* Utility to help print --version output in a consistent format.
2170754Sdelphij   Copyright (C) 1999-2004 Free Software Foundation, Inc.
3170754Sdelphij
4170754Sdelphij   This program is free software; you can redistribute it and/or modify
5170754Sdelphij   it under the terms of the GNU General Public License as published by
6170754Sdelphij   the Free Software Foundation; either version 2, or (at your option)
7170754Sdelphij   any later version.
8170754Sdelphij
9170754Sdelphij   This program is distributed in the hope that it will be useful,
10170754Sdelphij   but WITHOUT ANY WARRANTY; without even the implied warranty of
11170754Sdelphij   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12170754Sdelphij   GNU General Public License for more details.
13170754Sdelphij
14170754Sdelphij   You should have received a copy of the GNU General Public License
15170754Sdelphij   along with this program; if not, write to the Free Software Foundation,
16170754Sdelphij   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17170754Sdelphij
18170754Sdelphij/* Written by Jim Meyering. */
19170754Sdelphij
20170754Sdelphij#if HAVE_CONFIG_H
21170754Sdelphij# include <config.h>
22170754Sdelphij#endif
23170754Sdelphij
24170754Sdelphij/* Specification.  */
25170754Sdelphij#include "version-etc.h"
26170754Sdelphij
27170754Sdelphij#include <stdarg.h>
28170754Sdelphij#include <stdio.h>
29170754Sdelphij#include <stdlib.h>
30170754Sdelphij#include "unlocked-io.h"
31170754Sdelphij
32170754Sdelphij#include "gettext.h"
33170754Sdelphij#define _(msgid) gettext (msgid)
34170754Sdelphij
35170754Sdelphij/* Default copyright goes to the FSF. */
36170754Sdelphij
37170754Sdelphijconst char* version_etc_copyright =
38170754Sdelphij  /* Do *not* mark this string for translation.  */
39170754Sdelphij  "Copyright (C) 2004 Free Software Foundation, Inc.";
40170754Sdelphij
41170754Sdelphij
42170754Sdelphij/* Like version_etc, below, but with the NULL-terminated author list
43170754Sdelphij   provided via a variable of type va_list.  */
44170754Sdelphijvoid
45170754Sdelphijversion_etc_va (FILE *stream,
46170754Sdelphij		const char *command_name, const char *package,
47170754Sdelphij		const char *version, va_list authors)
48170754Sdelphij{
49170754Sdelphij  unsigned int n_authors;
50170754Sdelphij
51170754Sdelphij  /* Count the number of authors.  */
52170754Sdelphij  {
53170754Sdelphij    va_list tmp_authors;
54170754Sdelphij
55170754Sdelphij#ifdef __va_copy
56170754Sdelphij    __va_copy (tmp_authors, authors);
57170754Sdelphij#else
58170754Sdelphij    tmp_authors = authors;
59170754Sdelphij#endif
60170754Sdelphij
61170754Sdelphij    n_authors = 0;
62170754Sdelphij    while (va_arg (tmp_authors, const char *) != NULL)
63170754Sdelphij      ++n_authors;
64170754Sdelphij  }
65170754Sdelphij
66170754Sdelphij  if (command_name)
67170754Sdelphij    fprintf (stream, "%s (%s) %s\n", command_name, package, version);
68170754Sdelphij  else
69170754Sdelphij    fprintf (stream, "%s %s\n", package, version);
70170754Sdelphij
71170754Sdelphij  switch (n_authors)
72170754Sdelphij    {
73170754Sdelphij    case 0:
74170754Sdelphij      /* The caller must provide at least one author name.  */
75170754Sdelphij      abort ();
76170754Sdelphij    case 1:
77170754Sdelphij      /* TRANSLATORS: %s denotes an author name.  */
78170754Sdelphij      vfprintf (stream, _("Written by %s.\n"), authors);
79170754Sdelphij      break;
80170754Sdelphij    case 2:
81170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.  */
82170754Sdelphij      vfprintf (stream, _("Written by %s and %s.\n"), authors);
83170754Sdelphij      break;
84170754Sdelphij    case 3:
85170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.  */
86170754Sdelphij      vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
87170754Sdelphij      break;
88170754Sdelphij    case 4:
89170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
90170754Sdelphij	 You can use line breaks, estimating that each author name occupies
91170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
92170754Sdelphij      vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
93170754Sdelphij      break;
94170754Sdelphij    case 5:
95170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
96170754Sdelphij	 You can use line breaks, estimating that each author name occupies
97170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
98170754Sdelphij      vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
99170754Sdelphij      break;
100170754Sdelphij    case 6:
101170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
102170754Sdelphij	 You can use line breaks, estimating that each author name occupies
103170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
104170754Sdelphij      vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
105170754Sdelphij		authors);
106170754Sdelphij      break;
107170754Sdelphij    case 7:
108170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
109170754Sdelphij	 You can use line breaks, estimating that each author name occupies
110170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
111170754Sdelphij      vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
112170754Sdelphij		authors);
113170754Sdelphij      break;
114170754Sdelphij    case 8:
115170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
116170754Sdelphij	 You can use line breaks, estimating that each author name occupies
117170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
118170754Sdelphij      vfprintf (stream, _("\
119170754SdelphijWritten by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
120170754Sdelphij		authors);
121170754Sdelphij      break;
122170754Sdelphij    case 9:
123170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
124170754Sdelphij	 You can use line breaks, estimating that each author name occupies
125170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
126170754Sdelphij      vfprintf (stream, _("\
127170754SdelphijWritten by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
128170754Sdelphij		authors);
129170754Sdelphij      break;
130170754Sdelphij    default:
131170754Sdelphij      /* 10 or more authors.  Use an abbreviation, since the human reader
132170754Sdelphij	 will probably not want to read the entire list anyway.  */
133170754Sdelphij      /* TRANSLATORS: Each %s denotes an author name.
134170754Sdelphij	 You can use line breaks, estimating that each author name occupies
135170754Sdelphij	 ca. 16 screen columns and that a screen line has ca. 80 columns.  */
136170754Sdelphij      vfprintf (stream, _("\
137170754SdelphijWritten by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
138170754Sdelphij		authors);
139170754Sdelphij      break;
140170754Sdelphij    }
141170754Sdelphij  va_end (authors);
142170754Sdelphij  putc ('\n', stream);
143170754Sdelphij
144170754Sdelphij  fputs (version_etc_copyright, stream);
145170754Sdelphij  putc ('\n', stream);
146170754Sdelphij
147170754Sdelphij  fputs (_("\
148170754SdelphijThis is free software; see the source for copying conditions.  There is NO\n\
149170754Sdelphijwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
150170754Sdelphij	 stream);
151170754Sdelphij}
152170754Sdelphij
153170754Sdelphij
154170754Sdelphij/* Display the --version information the standard way.
155170754Sdelphij
156170754Sdelphij   If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
157170754Sdelphij   the program.  The formats are therefore:
158170754Sdelphij
159170754Sdelphij   PACKAGE VERSION
160170754Sdelphij
161170754Sdelphij   or
162170754Sdelphij
163170754Sdelphij   COMMAND_NAME (PACKAGE) VERSION.
164170754Sdelphij
165170754Sdelphij   The author names are passed as separate arguments, with an additional
166170754Sdelphij   NULL argument at the end.  */
167170754Sdelphijvoid
168170754Sdelphijversion_etc (FILE *stream,
169170754Sdelphij	     const char *command_name, const char *package,
170170754Sdelphij	     const char *version, /* const char *author1, ...*/ ...)
171170754Sdelphij{
172170754Sdelphij  va_list authors;
173170754Sdelphij
174170754Sdelphij  va_start (authors, version);
175170754Sdelphij  version_etc_va (stream, command_name, package, version, authors);
176170754Sdelphij}
177