| 1 |
/* printversion.c: Output for the standard GNU option --version. |
| 2 |
|
| 3 |
Written in 1996 by Karl Berry. Public domain. */ |
| 4 |
|
| 5 |
#include <w2c/config.h> |
| 6 |
#include "lib.h" |
| 7 |
#include <kpathsea/version.h> |
| 8 |
#ifdef PTEX |
| 9 |
#include <ptexenc/ptexenc.h> |
| 10 |
#endif |
| 11 |
|
| 12 |
/* We're passed in the original WEB banner string, which has the form |
| 13 |
This is PROGRAM, Version VERSION-NUMBER |
| 14 |
We parse the PROGRAM and VERSION-NUMBER out of this. |
| 15 |
|
| 16 |
If COPYRIGHT_HOLDER is specified and AUTHOR isn't, then use the |
| 17 |
former for the latter. If AUTHOR is specified and COPYRIGHT_HOLDER |
| 18 |
isn't, it means the original program is public domain. |
| 19 |
|
| 20 |
Maybe I should have just done it all inline in each individual |
| 21 |
program, but tangle doesn't allow multiline string constants ... */ |
| 22 |
|
| 23 |
void |
| 24 |
printversionandexit (const_string banner, |
| 25 |
const_string copyright_holder, |
| 26 |
const_string author, |
| 27 |
const_string extra_info) |
| 28 |
{ |
| 29 |
string prog_name; |
| 30 |
unsigned len; |
| 31 |
const_string prog_name_start; |
| 32 |
const_string prog_name_end = strchr (banner, ','); |
| 33 |
const_string prog_version = strrchr (banner, ' '); |
| 34 |
assert (prog_name_end && prog_version); |
| 35 |
prog_version++; |
| 36 |
|
| 37 |
len = prog_name_end - banner; |
| 38 |
prog_name = xmalloc (len + 1); |
| 39 |
strncpy (prog_name, banner, len); |
| 40 |
prog_name[len] = 0; |
| 41 |
|
| 42 |
prog_name_start = strrchr (prog_name, ' '); |
| 43 |
assert (prog_name_start); |
| 44 |
prog_name_start++; |
| 45 |
|
| 46 |
/* The Web2c version string starts with a space. */ |
| 47 |
#ifdef PTEX |
| 48 |
printf ("%s %s (%s)%s\n", prog_name_start, prog_version, get_enc_string(), |
| 49 |
versionstring); |
| 50 |
#else |
| 51 |
printf ("%s %s%s\n", prog_name_start, prog_version, versionstring); |
| 52 |
#endif |
| 53 |
puts (kpathsea_version_string); |
| 54 |
#ifdef PTEX |
| 55 |
puts (ptexenc_version_string); |
| 56 |
#endif |
| 57 |
|
| 58 |
if (copyright_holder) { |
| 59 |
printf ("Copyright 2026 %s.\n", copyright_holder); |
| 60 |
if (!author) |
| 61 |
author = copyright_holder; |
| 62 |
} |
| 63 |
|
| 64 |
puts ("There is NO warranty. Redistribution of this software is"); |
| 65 |
fputs ("covered by the terms of ", stdout); |
| 66 |
printf ("both the %s copyright and\n", prog_name_start); |
| 67 |
puts ("the Lesser GNU General Public License."); |
| 68 |
puts ("For more information about these matters, see the file"); |
| 69 |
printf ("named COPYING and the %s source.\n", prog_name_start); |
| 70 |
printf ("Primary author of %s: %s.\n", prog_name_start, author); |
| 71 |
|
| 72 |
if (extra_info) |
| 73 |
fputs (extra_info, stdout); |
| 74 |
|
| 75 |
free (prog_name); |
| 76 |
|
| 77 |
uexit (0); |
| 78 |
} |