summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/lib/printversion.c
blob: 8716e6db9946bfc9004fa2c632360452da1738d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* printversion.c: Output for the standard GNU option --version.

   Written in 1996 by Karl Berry.  Public domain.  */

#include <w2c/config.h>
#include "lib.h"
#include <kpathsea/version.h>
#ifdef PTEX
#include <ptexenc/ptexenc.h>
#endif

/* We're passed in the original WEB banner string, which has the form
This is PROGRAM, Version VERSION-NUMBER
   We parse the PROGRAM and VERSION-NUMBER out of this.
   
   If COPYRIGHT_HOLDER is specified and AUTHOR isn't, then use the
   former for the latter.  If AUTHOR is specified and COPYRIGHT_HOLDER
   isn't, it means the original program is public domain.
   
   Maybe I should have just done it all inline in each individual
   program, but tangle doesn't allow multiline string constants ...  */

void
printversionandexit (const_string banner,
                     const_string copyright_holder,  
                     const_string author,
                     const_string extra_info)
{
  string prog_name;
  unsigned len;
  const_string prog_name_start;
  const_string prog_name_end = strchr (banner, ',');
  const_string prog_version = strrchr (banner, ' ');
  assert (prog_name_end && prog_version);
  prog_version++;
  
  len = prog_name_end - banner;
  prog_name = xmalloc (len + 1);
  strncpy (prog_name, banner, len);
  prog_name[len] = 0;

  prog_name_start = strrchr (prog_name, ' ');
  assert (prog_name_start);
  prog_name_start++;

  /* The Web2c version string starts with a space.  */
#ifdef PTEX
  printf ("%s %s (%s)%s\n", prog_name_start, prog_version, get_enc_string(),
          versionstring);
#else
  printf ("%s %s%s\n", prog_name_start, prog_version, versionstring);
#endif
  puts (kpathsea_version_string);
#ifdef PTEX
  puts (ptexenc_version_string);
#endif

  if (copyright_holder) {
    printf ("Copyright 2021 %s.\n", copyright_holder);
    if (!author)
      author = copyright_holder;
  }

  puts ("There is NO warranty.  Redistribution of this software is");
  fputs ("covered by the terms of ", stdout);
  printf ("both the %s copyright and\n", prog_name_start);
  puts ("the Lesser GNU General Public License.");
  puts ("For more information about these matters, see the file");
  printf ("named COPYING and the %s source.\n", prog_name_start);
  printf ("Primary author of %s: %s.\n", prog_name_start, author);

  if (extra_info)
    fputs (extra_info, stdout);

  free (prog_name);

  uexit (0);
}