118fd37a7SXin LI /* Utility to help print --version output in a consistent format.
218fd37a7SXin LI Copyright (C) 1999-2004 Free Software Foundation, Inc.
318fd37a7SXin LI
418fd37a7SXin LI This program is free software; you can redistribute it and/or modify
518fd37a7SXin LI it under the terms of the GNU General Public License as published by
618fd37a7SXin LI the Free Software Foundation; either version 2, or (at your option)
718fd37a7SXin LI any later version.
818fd37a7SXin LI
918fd37a7SXin LI This program is distributed in the hope that it will be useful,
1018fd37a7SXin LI but WITHOUT ANY WARRANTY; without even the implied warranty of
1118fd37a7SXin LI MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1218fd37a7SXin LI GNU General Public License for more details.
1318fd37a7SXin LI
1418fd37a7SXin LI You should have received a copy of the GNU General Public License
1518fd37a7SXin LI along with this program; if not, write to the Free Software Foundation,
1618fd37a7SXin LI Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1718fd37a7SXin LI
1818fd37a7SXin LI /* Written by Jim Meyering. */
1918fd37a7SXin LI
2018fd37a7SXin LI #if HAVE_CONFIG_H
2118fd37a7SXin LI # include <config.h>
2218fd37a7SXin LI #endif
2318fd37a7SXin LI
2418fd37a7SXin LI /* Specification. */
2518fd37a7SXin LI #include "version-etc.h"
2618fd37a7SXin LI
2718fd37a7SXin LI #include <stdarg.h>
2818fd37a7SXin LI #include <stdio.h>
2918fd37a7SXin LI #include <stdlib.h>
3018fd37a7SXin LI #include "unlocked-io.h"
3118fd37a7SXin LI
3218fd37a7SXin LI #include "gettext.h"
3318fd37a7SXin LI #define _(msgid) gettext (msgid)
3418fd37a7SXin LI
3518fd37a7SXin LI /* Default copyright goes to the FSF. */
3618fd37a7SXin LI
3718fd37a7SXin LI const char* version_etc_copyright =
3818fd37a7SXin LI /* Do *not* mark this string for translation. */
3918fd37a7SXin LI "Copyright (C) 2004 Free Software Foundation, Inc.";
4018fd37a7SXin LI
4118fd37a7SXin LI
4218fd37a7SXin LI /* Like version_etc, below, but with the NULL-terminated author list
4318fd37a7SXin LI provided via a variable of type va_list. */
4418fd37a7SXin LI void
version_etc_va(FILE * stream,const char * command_name,const char * package,const char * version,va_list authors)4518fd37a7SXin LI version_etc_va (FILE *stream,
4618fd37a7SXin LI const char *command_name, const char *package,
4718fd37a7SXin LI const char *version, va_list authors)
4818fd37a7SXin LI {
4918fd37a7SXin LI unsigned int n_authors;
5018fd37a7SXin LI
5118fd37a7SXin LI /* Count the number of authors. */
5218fd37a7SXin LI {
5318fd37a7SXin LI va_list tmp_authors;
5418fd37a7SXin LI
5518fd37a7SXin LI #ifdef __va_copy
5618fd37a7SXin LI __va_copy (tmp_authors, authors);
5718fd37a7SXin LI #else
5818fd37a7SXin LI tmp_authors = authors;
5918fd37a7SXin LI #endif
6018fd37a7SXin LI
6118fd37a7SXin LI n_authors = 0;
6218fd37a7SXin LI while (va_arg (tmp_authors, const char *) != NULL)
6318fd37a7SXin LI ++n_authors;
6418fd37a7SXin LI }
6518fd37a7SXin LI
6618fd37a7SXin LI if (command_name)
6718fd37a7SXin LI fprintf (stream, "%s (%s) %s\n", command_name, package, version);
6818fd37a7SXin LI else
6918fd37a7SXin LI fprintf (stream, "%s %s\n", package, version);
7018fd37a7SXin LI
7118fd37a7SXin LI switch (n_authors)
7218fd37a7SXin LI {
7318fd37a7SXin LI case 0:
7418fd37a7SXin LI /* The caller must provide at least one author name. */
7518fd37a7SXin LI abort ();
7618fd37a7SXin LI case 1:
7718fd37a7SXin LI /* TRANSLATORS: %s denotes an author name. */
7818fd37a7SXin LI vfprintf (stream, _("Written by %s.\n"), authors);
7918fd37a7SXin LI break;
8018fd37a7SXin LI case 2:
8118fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name. */
8218fd37a7SXin LI vfprintf (stream, _("Written by %s and %s.\n"), authors);
8318fd37a7SXin LI break;
8418fd37a7SXin LI case 3:
8518fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name. */
8618fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
8718fd37a7SXin LI break;
8818fd37a7SXin LI case 4:
8918fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
9018fd37a7SXin LI You can use line breaks, estimating that each author name occupies
9118fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
9218fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
9318fd37a7SXin LI break;
9418fd37a7SXin LI case 5:
9518fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
9618fd37a7SXin LI You can use line breaks, estimating that each author name occupies
9718fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
9818fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
9918fd37a7SXin LI break;
10018fd37a7SXin LI case 6:
10118fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
10218fd37a7SXin LI You can use line breaks, estimating that each author name occupies
10318fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
10418fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
10518fd37a7SXin LI authors);
10618fd37a7SXin LI break;
10718fd37a7SXin LI case 7:
10818fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
10918fd37a7SXin LI You can use line breaks, estimating that each author name occupies
11018fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
11118fd37a7SXin LI vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
11218fd37a7SXin LI authors);
11318fd37a7SXin LI break;
11418fd37a7SXin LI case 8:
11518fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
11618fd37a7SXin LI You can use line breaks, estimating that each author name occupies
11718fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
11818fd37a7SXin LI vfprintf (stream, _("\
11918fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
12018fd37a7SXin LI authors);
12118fd37a7SXin LI break;
12218fd37a7SXin LI case 9:
12318fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
12418fd37a7SXin LI You can use line breaks, estimating that each author name occupies
12518fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
12618fd37a7SXin LI vfprintf (stream, _("\
12718fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
12818fd37a7SXin LI authors);
12918fd37a7SXin LI break;
13018fd37a7SXin LI default:
13118fd37a7SXin LI /* 10 or more authors. Use an abbreviation, since the human reader
13218fd37a7SXin LI will probably not want to read the entire list anyway. */
13318fd37a7SXin LI /* TRANSLATORS: Each %s denotes an author name.
13418fd37a7SXin LI You can use line breaks, estimating that each author name occupies
13518fd37a7SXin LI ca. 16 screen columns and that a screen line has ca. 80 columns. */
13618fd37a7SXin LI vfprintf (stream, _("\
13718fd37a7SXin LI Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
13818fd37a7SXin LI authors);
13918fd37a7SXin LI break;
14018fd37a7SXin LI }
14118fd37a7SXin LI va_end (authors);
14218fd37a7SXin LI putc ('\n', stream);
14318fd37a7SXin LI
14418fd37a7SXin LI fputs (version_etc_copyright, stream);
14518fd37a7SXin LI putc ('\n', stream);
14618fd37a7SXin LI
14718fd37a7SXin LI fputs (_("\
14818fd37a7SXin LI This is free software; see the source for copying conditions. There is NO\n\
14918fd37a7SXin LI warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
15018fd37a7SXin LI stream);
15118fd37a7SXin LI }
15218fd37a7SXin LI
15318fd37a7SXin LI
15418fd37a7SXin LI /* Display the --version information the standard way.
15518fd37a7SXin LI
15618fd37a7SXin LI If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
15718fd37a7SXin LI the program. The formats are therefore:
15818fd37a7SXin LI
15918fd37a7SXin LI PACKAGE VERSION
16018fd37a7SXin LI
16118fd37a7SXin LI or
16218fd37a7SXin LI
16318fd37a7SXin LI COMMAND_NAME (PACKAGE) VERSION.
16418fd37a7SXin LI
16518fd37a7SXin LI The author names are passed as separate arguments, with an additional
16618fd37a7SXin LI NULL argument at the end. */
16718fd37a7SXin LI void
version_etc(FILE * stream,const char * command_name,const char * package,const char * version,...)16818fd37a7SXin LI version_etc (FILE *stream,
16918fd37a7SXin LI const char *command_name, const char *package,
17018fd37a7SXin LI const char *version, /* const char *author1, ...*/ ...)
17118fd37a7SXin LI {
17218fd37a7SXin LI va_list authors;
17318fd37a7SXin LI
17418fd37a7SXin LI va_start (authors, version);
17518fd37a7SXin LI version_etc_va (stream, command_name, package, version, authors);
17618fd37a7SXin LI }
177