LCOV - code coverage report
Current view: top level - lib - version-etc.c (source / functions) Hit Total Coverage
Test: coreutils.info Lines: 25 49 51.0 %
Date: 2018-01-30 Functions: 2 2 100.0 %

          Line data    Source code
       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          83 : 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          83 :     va_copy (tmp_authors, authors);
      51             : 
      52          83 :     n_authors = 0;
      53         301 :     while (va_arg (tmp_authors, const char *) != NULL)
      54         135 :       ++n_authors;
      55             :   }
      56             : 
      57          83 :   if (command_name)
      58          83 :     fprintf (stream, "%s (%s) %s\n", command_name, package, version);
      59             :   else
      60           0 :     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          83 :   fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
      66             : 
      67          83 :   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          83 :   switch (n_authors)
      77             :     {
      78           0 :     case 0:
      79             :       /* The caller must provide at least one author name.  */
      80           0 :       abort ();
      81          46 :     case 1:
      82             :       /* TRANSLATORS: %s denotes an author name.  */
      83          46 :       vfprintf (stream, _("Written by %s.\n"), authors);
      84          46 :       break;
      85          22 :     case 2:
      86             :       /* TRANSLATORS: Each %s denotes an author name.  */
      87          22 :       vfprintf (stream, _("Written by %s and %s.\n"), authors);
      88          22 :       break;
      89          15 :     case 3:
      90             :       /* TRANSLATORS: Each %s denotes an author name.  */
      91          15 :       vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
      92          15 :       break;
      93           0 :     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           0 :       vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
      98           0 :       break;
      99           0 :     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           0 :       vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
     104           0 :       break;
     105           0 :     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           0 :       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
     110             :                 authors);
     111           0 :       break;
     112           0 :     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           0 :       vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
     117             :                 authors);
     118           0 :       break;
     119           0 :     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           0 :       vfprintf (stream, _("\
     124             : Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
     125             :                 authors);
     126           0 :       break;
     127           0 :     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           0 :       vfprintf (stream, _("\
     132             : Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
     133             :                 authors);
     134           0 :       break;
     135           0 :     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           0 :       vfprintf (stream, _("\
     142             : Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
     143             :                 authors);
     144           0 :       break;
     145             :     }
     146          83 :   va_end (authors);
     147          83 : }
     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          56 : 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          56 :   va_start (authors, version);
     171          56 :   version_etc_va (stream, command_name, package, version, authors);
     172          56 : }

Generated by: LCOV version 1.10