summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-update-docindex
blob: 03bcffcf03c66238e74af9b2cab5e5885d62dea4 (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
#!/usr/bin/env perl
# $Id$
# Make index file of all HTML and PDF documentation (printed on stdout).
# Originally written 2004, Karl Berry.  Public domain.

exit (&main ());

sub main
{
  (my $progname = $0) =~ s,^.*/,,;
  umask (0);
  $ENV{'LC_ALL'} = 'C'; # for the date command used below
  
  chomp (my $mydir = `dirname $0`);
  chdir ("$mydir/../..") || exit 1;    # Master

  # shell fragment we use to find doc files in a directory.
  $ENV{"_POSIX2_VERSION"} = 0;  # POSIX likes to be backward-incompatible
  $FIND_POST = "   \\( -name \\*.html -o -name \\*.pdf \\) "
               . " | tee /tmp/doclist"
               . " | sort -f -t/ +2 |";

  print <<END_HEADER;
<html>
<body>
<h1>TeX Live documentation</h1>

<p>This document lists links to all HTML and PDF files for packages and guides
contained in TeX Live (in the <a href="texmf/">texmf</a> and <a
href="texmf-dist/">texmf-dist</a> directories), sorted by package name.</p>
END_HEADER

  &do_package_list ();
  
  chomp (my $date = `date`);
  print <<END_TRAILER;
<hr>
<small>Generated $date by $progname.</small>
</body></html>
END_TRAILER
  
  return 0;
}



# Package doc (texmf and texmf-dist), by package.
# 
sub do_package_list
{
  &do_filelist ("find texmf/doc texmf-dist/doc $FIND_POST");
}



# Process all files resulting from OPENCMD.
# 
sub do_filelist
{
  my ($opencmd) = @_;
  
  print "\n<ol>\n";
  my $prevdir = "";
  my @entries = ();
  
  $FILELIST = $opencmd;
  open (FILELIST) || die "open($FILELIST) failed: $!";
  while (<FILELIST>) {
    chomp;
    # collect all files for a given directory
    (my $thisdir = $_) =~ s,/[^/]*$,,;

    if ($thisdir eq $prevdir) {
      push (@entries, $_);
    } else {
      &do_directory ($prevdir, @entries) if $prevdir;  # avoid first empty 
      $prevdir = $thisdir;
      @entries = ($_);
    }
  }
  close (FILELIST) || warn "close($FILELIST) failed: $!";
  
  &do_directory ($prevdir, @entries);  # include last

  print "\n</ol>\n";
}



# Print doc ENTRIES in DIR.
# 
sub do_directory
{
  my ($dir,@entries) = @_;
  
  # $dir includes the texmf tree, e.g.,
  #   texmf-dist/doc/allrunes
  # This is too ugly.  We just want to show allrunes, especially since
  # that's what we sorted by.
  my (undef,undef,$nicename) = split (/\//, $dir, 3);

  print qq!<li><b><a href="$dir">$nicename</a>!;
  
  # if we have an index.html or a live.html, make things nicer.
  if (grep { m,/(index|live)\.html$, } @entries) {
     # first remove all .html's.
     @entries = grep { $_ !~ /\.html$/
                       || $_ =~ m,/(index|live)\.html, } @entries;

     # if only one entry left, remove it, the directory link suffices.
     @entries = () if $entries[0] =~ m,/index\.html$, && @entries == 1;
  }
  
  # if we're going to print anything, insert punctuation.
  print ":" if @entries;
  print "</b><small>\n";
  
  for my $e (@entries) {
    (my $basename = $e) =~ s,.*/,,;
    print qq!  <a href="$e">$basename</a>\n!;
  }

  print "  </small>\n\n";
}