summaryrefslogtreecommitdiff
path: root/Build/tools/tlpkginfo
blob: 3630f31ac529927a886ab8eb6db4ab0d5dc9a59b (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env perl
# $Id$
# Return information given a TL package name (i.e., a tpm file name).
# Currently just the ctan directory for package, but maybe we'll do more
# later.
# 
exit (&main ());

sub main
{
  $CTAN = $ENV{"CTAN"} || "/home/ftp/tex-archive";
  $CATALOGUE = $ENV{"TEX_CATALOGUE"} || "/home/httpd/html/catalogue/entries";
  
  if ($ARGV[0] eq "--ctan-dir") {
    return &find_ctan_dir ($ARGV[1]);
  } else {
    die "$0: only know about --ctan-dir PKGNAME.\n";
  }
}


# 
# Return 0 for success if we find a path (and print it on stdout), else
# return 1.
# 
sub find_ctan_dir
{
  my ($me) = @_;
  return 1 unless $me;  
  
  # The CTAN path to a package is sometimes stored in the TeX Catalogue,
  # but old entries don't have it, etc.  Still, we want to use it if present.
  my $ctan_dir = &catalogue_find_ctan_path ($me);
  if (! $ctan_dir) {
    # fall back on many special cases
    (my $menobin = $me) =~ s,^bin-,,;
    (my $menodash = $me) =~ s,^.*-,,;
    (my $menopowerdot = $me) =~ s,^powerdot-,,;
    (my $menotype1 = $me) =~ s,-type1$,,;

    for my $dir (
      "macros/latex/contrib/$me",			# most everything
      "macros/latex/contrib/\L$me",		# HA-prosper
      "macros/latex/contrib/powerdot/contrib/$menopowerdot", # powerdot-doc-vn
      "macros/latex/exptl/$me",			# semioneside
      "macros/latex/required/$me",		# babel
      "macros/plain/$me",				# plnfss
      "macros/xetex/latex/$me",			# xetex
      "macros/generic/$me",			# abbr
      "macros/generic/diagrams/$me",		# circ
      "macros/$me",				# eplain
      "support/$me",				# thumbpdf
      "support/$menobin",				# bin-thumbpdf
      "language/vietnamese/$me/unpacked",		# vntex
      "language/hyphenation/$me",			# bghyphen
      "language/hebrew/$me",			# cjhebrew
      "language/greek/package-babel/$me",		# ibycus-babel
      "language/coptic/$me",			# cbcoptic
      "info/math/voss/$me",			# mathmode
      "info/lshort/$menodash",			# lshort-english
      "info/bibtex/$me",				# tamethebeast
      "info/symbols/$me",				# comprehensive
      "info/$me",					# Type1fonts
      "graphics/$me",				# sparklines
      "graphics/metapost/contrib/macros/$me",	# mpattern
      "graphics/pstricks/contrib/pedigree/$me",	# pst-pdgr
      "graphics/pstricks/contrib/$me",		# pstricks-add
      "fonts/$me",				# MnSymbol
      "fonts/utilities/$me",			# accfonts
      "fonts/ps-type1/$me",			# cm-super
      "fonts/ps-type1/$menotype1",		# esint-type1
      "fonts/greek/$me",				# lfb
      "fonts/gothic/$me",				# blacklettert1
      "fonts/cyrillic/$me/texmf",			# lh
      "fonts/chess/$me",				# skaknew
      "biblio/bibtex/contrib/$me",		# dk-bib
                 ) {
      if (-d "$CTAN/$dir") {
        $ctan_dir = $dir;
        last;
      }
    }

    # names totally dissimilar
    $ctan_dir = "fonts/fourier-GUT" if $me eq "fourier";
    $ctan_dir = "info/biblio" if $me eq "beebe";
    $ctan_dir = "info/italian/amsldoc" if $me eq "amsldoc-it";
    $ctan_dir = "info/italian/amsthdoc" if $me eq "amsthdoc-it";
    $ctan_dir = "info/tex-references" if $me eq "tex-refs";
    $ctan_dir = "language/basque" if $me eq "hyphen-basque";
    $ctan_dir = "language/devanagari/velthuis" if $me eq "devanagr";
    $ctan_dir = "language/hyphenation" if $me eq "hyphen-german";
    $ctan_dir = "language/hyphenation/elhyphen" if $me eq "hyphen-greek";
    $ctan_dir = "macros/latex/contrib/misc" if $me eq "ltxmisc";
    $ctan_dir = "macros/generic" if $me eq "genmisc";

    # do last, for sake of subdirs above.
    $ctan_dir = "language/hyphenation"
      if $me =~ /^hyphen-/ && ! $ctan_dir;
  }
  
  print "$CTAN/$ctan_dir\n" if $ctan_dir;
  return $ctan_dir ? 0 : 1;
}


# look up ctan path for given package name in catalogue entry.
# xml is too hard to parse, so just look for the <ctan path...> entry.
# Sometimes there is a single file, but worry about that later.
# 
# Return the ctan path if found (without leading /), or undef.
# 
sub catalogue_find_ctan_path
{
  my ($pkgname) = @_;
  
  my $firstchar = substr ($pkgname, 0, 1);
  my $catfile =  "$CATALOGUE/$firstchar/$pkgname.xml";
  return undef unless -r $catfile;

  my $ctan_path = `sed -n -e "s,'/>,," -e "s,^ *<ctan path='/,,p" $catfile`;
  return undef unless $ctan_path;

  chomp ($ctan_path);
  return $ctan_path;
}