]> git.cworth.org Git - tar/blob - lib/version-etc.c
823e08562c0409b59d35a1faf05f859d03af09cc
[tar] / lib / version-etc.c
1 /* Utility to help print --version output in a consistent format.
2    Copyright (C) 1999-2008 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 3 of the License, or
7    (at your option) 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, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Jim Meyering. */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "version-etc.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #if USE_UNLOCKED_IO
29 # include "unlocked-io.h"
30 #endif
31
32 #include "gettext.h"
33 #define _(msgid) gettext (msgid)
34
35 enum { COPYRIGHT_YEAR = 2008 };
36
37 /* Like version_etc, below, but with the NULL-terminated author list
38    provided via a variable of type va_list.  */
39 void
40 version_etc_va (FILE *stream,
41                 const char *command_name, const char *package,
42                 const char *version, va_list authors)
43 {
44   size_t n_authors;
45
46   /* Count the number of authors.  */
47   {
48     va_list tmp_authors;
49
50     va_copy (tmp_authors, authors);
51
52     n_authors = 0;
53     while (va_arg (tmp_authors, const char *) != NULL)
54       ++n_authors;
55   }
56
57   if (command_name)
58     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
59   else
60     fprintf (stream, "%s %s\n", package, version);
61
62   /* TRANSLATORS: Translate "(C)" to the copyright symbol
63      (C-in-a-circle), if this symbol is available in the user's
64      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
65   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
66
67   fputs (_("\
68 \n\
69 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
70 This is free software: you are free to change and redistribute it.\n\
71 There is NO WARRANTY, to the extent permitted by law.\n\
72 \n\
73 "),
74          stream);
75
76   switch (n_authors)
77     {
78     case 0:
79       /* The caller must provide at least one author name.  */
80       abort ();
81     case 1:
82       /* TRANSLATORS: %s denotes an author name.  */
83       vfprintf (stream, _("Written by %s.\n"), authors);
84       break;
85     case 2:
86       /* TRANSLATORS: Each %s denotes an author name.  */
87       vfprintf (stream, _("Written by %s and %s.\n"), authors);
88       break;
89     case 3:
90       /* TRANSLATORS: Each %s denotes an author name.  */
91       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
92       break;
93     case 4:
94       /* TRANSLATORS: Each %s denotes an author name.
95          You can use line breaks, estimating that each author name occupies
96          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
97       vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
98       break;
99     case 5:
100       /* TRANSLATORS: Each %s denotes an author name.
101          You can use line breaks, estimating that each author name occupies
102          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
103       vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
104       break;
105     case 6:
106       /* TRANSLATORS: Each %s denotes an author name.
107          You can use line breaks, estimating that each author name occupies
108          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
109       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
110                 authors);
111       break;
112     case 7:
113       /* TRANSLATORS: Each %s denotes an author name.
114          You can use line breaks, estimating that each author name occupies
115          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
116       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
117                 authors);
118       break;
119     case 8:
120       /* TRANSLATORS: Each %s denotes an author name.
121          You can use line breaks, estimating that each author name occupies
122          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
123       vfprintf (stream, _("\
124 Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
125                 authors);
126       break;
127     case 9:
128       /* TRANSLATORS: Each %s denotes an author name.
129          You can use line breaks, estimating that each author name occupies
130          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
131       vfprintf (stream, _("\
132 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
133                 authors);
134       break;
135     default:
136       /* 10 or more authors.  Use an abbreviation, since the human reader
137          will probably not want to read the entire list anyway.  */
138       /* TRANSLATORS: Each %s denotes an author name.
139          You can use line breaks, estimating that each author name occupies
140          ca. 16 screen columns and that a screen line has ca. 80 columns.  */
141       vfprintf (stream, _("\
142 Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
143                 authors);
144       break;
145     }
146   va_end (authors);
147 }
148
149
150 /* Display the --version information the standard way.
151
152    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
153    the program.  The formats are therefore:
154
155    PACKAGE VERSION
156
157    or
158
159    COMMAND_NAME (PACKAGE) VERSION.
160
161    The author names are passed as separate arguments, with an additional
162    NULL argument at the end.  */
163 void
164 version_etc (FILE *stream,
165              const char *command_name, const char *package,
166              const char *version, /* const char *author1, ...*/ ...)
167 {
168   va_list authors;
169
170   va_start (authors, version);
171   version_etc_va (stream, command_name, package, version, authors);
172 }