]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gnu-sort/lib/version-etc.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gnu-sort / lib / version-etc.c
1 /* Utility to help print --version output in a consistent format.
2    Copyright (C) 1999-2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 /* $FreeBSD$ */
19
20 /* Written by Jim Meyering. */
21
22 #if HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 /* Specification.  */
27 #include "version-etc.h"
28
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "unlocked-io.h"
33
34 #include "gettext.h"
35 #define _(msgid) gettext (msgid)
36
37 /* Default copyright goes to the FSF. */
38
39 const char* version_etc_copyright =
40   /* Do *not* mark this string for translation.  */
41   "Copyright (C) 2004 Free Software Foundation, Inc.";
42
43
44 /* Like version_etc, below, but with the NULL-terminated author list
45    provided via a variable of type va_list.  */
46 void
47 version_etc_va (FILE *stream,
48                 const char *command_name, const char *package,
49                 const char *version, va_list authors)
50 {
51   size_t n_authors;
52
53   /* Count the number of authors.  */
54   {
55     va_list tmp_authors;
56
57 #ifdef va_copy
58     va_copy (tmp_authors, authors);
59 #else
60     tmp_authors = authors;
61 #endif
62
63     n_authors = 0;
64     while (va_arg (tmp_authors, const char *) != NULL)
65       ++n_authors;
66 #ifdef va_copy
67     va_end (tmp_authors);
68 #endif
69   }
70
71   if (command_name)
72     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
73   else
74     fprintf (stream, "%s %s\n", package, version);
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   putc ('\n', stream);
148
149   fputs (version_etc_copyright, stream);
150   putc ('\n', stream);
151
152   fputs (_("\
153 This is free software; see the source for copying conditions.  There is NO\n\
154 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
155          stream);
156 }
157
158
159 /* Display the --version information the standard way.
160
161    If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
162    the program.  The formats are therefore:
163
164    PACKAGE VERSION
165
166    or
167
168    COMMAND_NAME (PACKAGE) VERSION.
169
170    The author names are passed as separate arguments, with an additional
171    NULL argument at the end.  */
172 void
173 version_etc (FILE *stream,
174              const char *command_name, const char *package,
175              const char *version, /* const char *author1, ...*/ ...)
176 {
177   va_list authors;
178
179   va_start (authors, version);
180   version_etc_va (stream, command_name, package, version, authors);
181 }