version-etc.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* Print --version and bug-reporting information in a consistent format.
  2. Copyright (C) 1999-2013 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /* Written by Jim Meyering. */
  14. #include <config.h>
  15. /* Specification. */
  16. #include "version-etc.h"
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #if USE_UNLOCKED_IO
  21. # include "unlocked-io.h"
  22. #endif
  23. #include "gettext.h"
  24. #define _(msgid) gettext (msgid)
  25. /* If you use AM_INIT_AUTOMAKE's no-define option,
  26. PACKAGE is not defined. Use PACKAGE_TARNAME instead. */
  27. #if ! defined PACKAGE && defined PACKAGE_TARNAME
  28. # define PACKAGE PACKAGE_TARNAME
  29. #endif
  30. enum { COPYRIGHT_YEAR = 2013 };
  31. /* The three functions below display the --version information the
  32. standard way.
  33. If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
  34. the program. The formats are therefore:
  35. PACKAGE VERSION
  36. or
  37. COMMAND_NAME (PACKAGE) VERSION.
  38. The functions differ in the way they are passed author names. */
  39. /* Display the --version information the standard way.
  40. Author names are given in the array AUTHORS. N_AUTHORS is the
  41. number of elements in the array. */
  42. void
  43. version_etc_arn (FILE *stream,
  44. const char *command_name, const char *package,
  45. const char *version,
  46. const char * const * authors, size_t n_authors)
  47. {
  48. if (command_name)
  49. fprintf (stream, "%s (%s) %s\n", command_name, package, version);
  50. else
  51. fprintf (stream, "%s %s\n", package, version);
  52. #ifdef PACKAGE_PACKAGER
  53. # ifdef PACKAGE_PACKAGER_VERSION
  54. fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
  55. PACKAGE_PACKAGER_VERSION);
  56. # else
  57. fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
  58. # endif
  59. #endif
  60. /* TRANSLATORS: Translate "(C)" to the copyright symbol
  61. (C-in-a-circle), if this symbol is available in the user's
  62. locale. Otherwise, do not translate "(C)"; leave it as-is. */
  63. fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
  64. fputs (_("\
  65. \n\
  66. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
  67. This is free software: you are free to change and redistribute it.\n\
  68. There is NO WARRANTY, to the extent permitted by law.\n\
  69. \n\
  70. "),
  71. stream);
  72. switch (n_authors)
  73. {
  74. case 0:
  75. /* The caller must provide at least one author name. */
  76. abort ();
  77. case 1:
  78. /* TRANSLATORS: %s denotes an author name. */
  79. fprintf (stream, _("Written by %s.\n"), authors[0]);
  80. break;
  81. case 2:
  82. /* TRANSLATORS: Each %s denotes an author name. */
  83. fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
  84. break;
  85. case 3:
  86. /* TRANSLATORS: Each %s denotes an author name. */
  87. fprintf (stream, _("Written by %s, %s, and %s.\n"),
  88. authors[0], authors[1], authors[2]);
  89. break;
  90. case 4:
  91. /* TRANSLATORS: Each %s denotes an author name.
  92. You can use line breaks, estimating that each author name occupies
  93. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  94. fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
  95. authors[0], authors[1], authors[2], authors[3]);
  96. break;
  97. case 5:
  98. /* TRANSLATORS: Each %s denotes an author name.
  99. You can use line breaks, estimating that each author name occupies
  100. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  101. fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
  102. authors[0], authors[1], authors[2], authors[3], authors[4]);
  103. break;
  104. case 6:
  105. /* TRANSLATORS: Each %s denotes an author name.
  106. You can use line breaks, estimating that each author name occupies
  107. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  108. fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
  109. authors[0], authors[1], authors[2], authors[3], authors[4],
  110. authors[5]);
  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. fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
  117. authors[0], authors[1], authors[2], authors[3], authors[4],
  118. authors[5], authors[6]);
  119. break;
  120. case 8:
  121. /* TRANSLATORS: Each %s denotes an author name.
  122. You can use line breaks, estimating that each author name occupies
  123. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  124. fprintf (stream, _("\
  125. Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
  126. authors[0], authors[1], authors[2], authors[3], authors[4],
  127. authors[5], authors[6], authors[7]);
  128. break;
  129. case 9:
  130. /* TRANSLATORS: Each %s denotes an author name.
  131. You can use line breaks, estimating that each author name occupies
  132. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  133. fprintf (stream, _("\
  134. Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
  135. authors[0], authors[1], authors[2], authors[3], authors[4],
  136. authors[5], authors[6], authors[7], authors[8]);
  137. break;
  138. default:
  139. /* 10 or more authors. Use an abbreviation, since the human reader
  140. will probably not want to read the entire list anyway. */
  141. /* TRANSLATORS: Each %s denotes an author name.
  142. You can use line breaks, estimating that each author name occupies
  143. ca. 16 screen columns and that a screen line has ca. 80 columns. */
  144. fprintf (stream, _("\
  145. Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
  146. authors[0], authors[1], authors[2], authors[3], authors[4],
  147. authors[5], authors[6], authors[7], authors[8]);
  148. break;
  149. }
  150. }
  151. /* Display the --version information the standard way. See the initial
  152. comment to this module, for more information.
  153. Author names are given in the NULL-terminated array AUTHORS. */
  154. void
  155. version_etc_ar (FILE *stream,
  156. const char *command_name, const char *package,
  157. const char *version, const char * const * authors)
  158. {
  159. size_t n_authors;
  160. for (n_authors = 0; authors[n_authors]; n_authors++)
  161. ;
  162. version_etc_arn (stream, command_name, package, version, authors, n_authors);
  163. }
  164. /* Display the --version information the standard way. See the initial
  165. comment to this module, for more information.
  166. Author names are given in the NULL-terminated va_list AUTHORS. */
  167. void
  168. version_etc_va (FILE *stream,
  169. const char *command_name, const char *package,
  170. const char *version, va_list authors)
  171. {
  172. size_t n_authors;
  173. const char *authtab[10];
  174. for (n_authors = 0;
  175. n_authors < 10
  176. && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
  177. n_authors++)
  178. ;
  179. version_etc_arn (stream, command_name, package, version,
  180. authtab, n_authors);
  181. }
  182. /* Display the --version information the standard way.
  183. If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
  184. the program. The formats are therefore:
  185. PACKAGE VERSION
  186. or
  187. COMMAND_NAME (PACKAGE) VERSION.
  188. The authors names are passed as separate arguments, with an additional
  189. NULL argument at the end. */
  190. void
  191. version_etc (FILE *stream,
  192. const char *command_name, const char *package,
  193. const char *version, /* const char *author1, ...*/ ...)
  194. {
  195. va_list authors;
  196. va_start (authors, version);
  197. version_etc_va (stream, command_name, package, version, authors);
  198. va_end (authors);
  199. }
  200. void
  201. emit_bug_reporting_address (void)
  202. {
  203. /* TRANSLATORS: The placeholder indicates the bug-reporting address
  204. for this package. Please add _another line_ saying
  205. "Report translation bugs to <...>\n" with the address for translation
  206. bugs (typically your translation team's web or email address). */
  207. printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
  208. #ifdef PACKAGE_PACKAGER_BUG_REPORTS
  209. printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
  210. PACKAGE_PACKAGER_BUG_REPORTS);
  211. #endif
  212. #ifdef PACKAGE_URL
  213. printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
  214. #else
  215. printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"),
  216. PACKAGE_NAME, PACKAGE);
  217. #endif
  218. fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
  219. stdout);
  220. }