#!/usr/bin/perl -w # # $Id: wntitle,v 1.2+1 2000/08/07 20:59:10 vogelke Exp $ # # wntitle: read index.cache, add descriptions to Apache-generated # index. To use, save the Apache-generated index as index.htm or # index.html, run wndex to make index.cache, then run this. # # The original index is overwritten, and a tag is added to # keep this script from trying to modify an already-modified index. ($myname) = split(/\//, reverse($0)); $myname = reverse($myname); # script basename. $mstr = ""; open(C, "index.cache") || die "index.cache: $!\n"; while () { chomp; if (/^file=(.*).content=text.html.title=(.*)$/) { $file = $1; $title = $2; $t{$file} = "$title"; } } close(C); $idx = ""; $idx = "index.htm" if -f "index.htm"; $idx = "index.html" if -f "index.html"; die "no index file" unless length($idx) > 0; $newidx = "index$$.htm"; open(OUT, "> $newidx") || die "$newidx: $!\n"; open(H, "$idx") || die "$idx: $!\n"; while () { chomp; if (/$mstr/) { close(H); close(OUT); unlink($newidx); die "$idx has already been generated by this script\n"; } if (/A HREF="(.*)"/) { $file = $1; if (scalar($t{$file})) { $_ .= "$t{$file}"; } } print OUT "$_\n"; } close(H); close(OUT); rename($newidx, $idx); exit(0);