1*18fd37a7SXin LI /* Utility to help print --version output in a consistent format.
2*18fd37a7SXin LI Copyright (C) 1999-2004 Free Software Foundation, Inc.
3*18fd37a7SXin LI
4*18fd37a7SXin LI This program is free software; you can redistribute it and/or modify
5*18fd37a7SXin LI it under the terms of the GNU General Public License as published by
6*18fd37a7SXin LI the Free Software Foundation; either version 2, or (at your option)
7*18fd37a7SXin LI any later version.
8*18fd37a7SXin LI
9*18fd37a7SXin LI This program is distributed in the hope that it will be useful,
10*18fd37a7SXin LI but WITHOUT ANY WARRANTY; without even the implied warranty of
11*18fd37a7SXin LI MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*18fd37a7SXin LI GNU General Public License for more details.
13*18fd37a7SXin LI
14*18fd37a7SXin LI You should have received a copy of the GNU General Public License
15*18fd37a7SXin LI along with this program; if not, write to the Free Software Foundation,
16*18fd37a7SXin LI Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17*18fd37a7SXin LI
18*18fd37a7SXin LI /* Written by Jim Meyering. */
19*18fd37a7SXin LI
20*18fd37a7SXin LI #if HAVE_CONFIG_H
21*18fd37a7SXin LI # include <config.h>
22*18fd37a7SXin LI #endif
23*18fd37a7SXin LI
24*18fd37a7SXin LI /* Specification. */
25*18fd37a7SXin LI #include "version-etc.h"
26*18fd37a7SXin LI
27*18fd37a7SXin LI #include <stdarg.h>
28*18fd37a7SXin LI #include <stdio.h>
29*18fd37a7SXin LI #include <stdlib.h>
30*18fd37a7SXin LI #include "unlocked-io.h"
31*18fd37a7SXin LI
32*18fd37a7SXin LI #include "gettext.h"
33*18fd37a7SXin LI #define _(msgid) gettext (msgid)
34*18fd37a7SXin LI
35*18fd37a7SXin LI /* Default copyright goes to the FSF. */
36*18fd37a7SXin LI
37*18fd37a7SXin LI const char* version_etc_copyright =
38*18fd37a7SXin LI /* Do *not* mark this string for translation. */
39*18fd37a7SXin LI "Copyright (C) 2004 Free Software Foundation, Inc.";
40*18fd37a7SXin LI
41*18fd37a7SXin LI
42*18fd37a7SXin LI /* Like version_etc, below, but with the NULL-terminated author list
43*18fd37a7SXin LI provided via a variable of type va_list. */
44*18fd37a7SXin LI void
version_etc_va(FILE * stream,const char * command_name,const char * package,const char * version,va_list authors)45*18fd37a7SXin LI version_etc_va (FILE *stream,
46*18fd37a7SXin LI const char *command_name, const char *package,
47*18fd37a7SXin LI const char *version, va_list authors)
48*18fd37a7SXin LI {
49*18fd37a7SXin LI unsigned int n_authors;
50*18fd37a7SXin LI
51*18fd37a7SXin LI /* Count the number of authors. */
52*18fd37a7SXin LI {
53*18fd37a7SXin LI va_list tmp_authors;
54*18fd37a7SXin LI
55*18fd37a7SXin LI #ifdef __va_copy
56*18fd37a7SXin LI __va_copy (tmp_authors, authors);
57*18fd37a7SXin LI #else
58*18fd37a7SXin LI tmp_authors = authors;
59*18fd37a7SXin LI #endif
60*18fd37a7SXin LI
61*18fd37a7SXin LI n_authors = 0;
62*18fd37a7SXin LI while (va_arg (tmp_authors, const char *) != NULL)
63*18fd37a7SXin LI ++n_authors;
64*18fd37a7SXin LI }
65*18fd37a7SXin LI
66*18fd37a7SXin LI if (command_name)
67*18fd37a7SXin LI fprintf (stream, "%s (%s) %s\n", command_name, package, version);
68*18fd37a7SXin LI else
69*18fd37a7SXin LI fprintf (stream, "%s %s\n", package, version);
70*18fd37a7SXin LI
71*18fd37a7SXin LI switch (n_authors)
72*18fd37a7SXin LI {
73*18fd37a7SXin LI case 0:
74*18fd37a7SXin LI /* The caller must provide at least one author name. */
75*18fd37a7SXin LI abort ();
76*18fd37a7SXin LI case 1:
77*18fd37a7SXin LI /* TRANSLATORS: %s denotes an author name. */
78*18fd37a7SXin LI vfprintf (stream, _("Written by %s.\n"), authors);
79*18fd37a7SXin LI break;
80*18fd37a7SXin LI case 2:
81*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name. */
82*18fd37a7SXin LI vfprintf (stream, _("Written by %s and %s.\n"), authors);
83*18fd37a7SXin LI break;
84*18fd37a7SXin LI case 3:
85*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name. */
86*18fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
87*18fd37a7SXin LI break;
88*18fd37a7SXin LI case 4:
89*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
90*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
91*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
92*18fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
93*18fd37a7SXin LI break;
94*18fd37a7SXin LI case 5:
95*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
96*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
97*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
98*18fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
99*18fd37a7SXin LI break;
100*18fd37a7SXin LI case 6:
101*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
102*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
103*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
104*18fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
105*18fd37a7SXin LI authors);
106*18fd37a7SXin LI break;
107*18fd37a7SXin LI case 7:
108*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
109*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
110*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
111*18fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
112*18fd37a7SXin LI authors);
113*18fd37a7SXin LI break;
114*18fd37a7SXin LI case 8:
115*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
116*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
117*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
118*18fd37a7SXin LI vfprintf (stream, _("\
119*18fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
120*18fd37a7SXin LI authors);
121*18fd37a7SXin LI break;
122*18fd37a7SXin LI case 9:
123*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
124*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
125*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
126*18fd37a7SXin LI vfprintf (stream, _("\
127*18fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
128*18fd37a7SXin LI authors);
129*18fd37a7SXin LI break;
130*18fd37a7SXin LI default:
131*18fd37a7SXin LI /* 10 or more authors. Use an abbreviation, since the human reader
132*18fd37a7SXin LI will probably not want to read the entire list anyway. */
133*18fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
134*18fd37a7SXin LI You can use line breaks, estimating that each author name occupies
135*18fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
136*18fd37a7SXin LI vfprintf (stream, _("\
137*18fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
138*18fd37a7SXin LI authors);
139*18fd37a7SXin LI break;
140*18fd37a7SXin LI }
141*18fd37a7SXin LI va_end (authors);
142*18fd37a7SXin LI putc ('\n', stream);
143*18fd37a7SXin LI
144*18fd37a7SXin LI fputs (version_etc_copyright, stream);
145*18fd37a7SXin LI putc ('\n', stream);
146*18fd37a7SXin LI
147*18fd37a7SXin LI fputs (_("\
148*18fd37a7SXin LI This is free software; see the source for copying conditions. There is NO\n\
149*18fd37a7SXin LI warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
150*18fd37a7SXin LI stream);
151*18fd37a7SXin LI }
152*18fd37a7SXin LI
153*18fd37a7SXin LI
154*18fd37a7SXin LI /* Display the --version information the standard way.
155*18fd37a7SXin LI
156*18fd37a7SXin LI If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
157*18fd37a7SXin LI the program. The formats are therefore:
158*18fd37a7SXin LI
159*18fd37a7SXin LI PACKAGE VERSION
160*18fd37a7SXin LI
161*18fd37a7SXin LI or
162*18fd37a7SXin LI
163*18fd37a7SXin LI COMMAND_NAME (PACKAGE) VERSION.
164*18fd37a7SXin LI
165*18fd37a7SXin LI The author names are passed as separate arguments, with an additional
166*18fd37a7SXin LI NULL argument at the end. */
167*18fd37a7SXin LI void
version_etc(FILE * stream,const char * command_name,const char * package,const char * version,...)168*18fd37a7SXin LI version_etc (FILE *stream,
169*18fd37a7SXin LI const char *command_name, const char *package,
170*18fd37a7SXin LI const char *version, /* const char *author1, ...*/ ...)
171*18fd37a7SXin LI {
172*18fd37a7SXin LI va_list authors;
173*18fd37a7SXin LI
174*18fd37a7SXin LI va_start (authors, version);
175*18fd37a7SXin LI version_etc_va (stream, command_name, package, version, authors);
176*18fd37a7SXin LI }
177