<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/local/bin/perl
#
# $Date: 1997/05/15 16:06:29 $ 

$tocfile = shift @ARGV;
system("/bin/cp $tocfile $tocfile.$$");
open(IN, "$tocfile.$$") or die "Unable to open $tocfile\n";
open(OUT, "&gt;$tocfile") or die "Unable to create $tocfile\n";

while (&lt;IN&gt;) {
    print OUT $_;
    if (/&lt;!--X-TOC-Start--&gt;/) {
	while (&lt;IN&gt;) {
	    last if (/&lt;!--X-TOC-End--&gt;/);
	}
	foreach $file (@ARGV) {
	    open(FILE, $file) or die "Unable to open $file\n";

	    print OUT "&lt;ul&gt;\n";
	    while (&lt;FILE&gt;) {
		chomp;
		next  unless m|&lt;h2|i;
		($id) = m|name="(.*?)"|i;
		s|&lt;/?h\d.*?&gt;||gi; s|&lt;/?a.*?&gt;||gi;
		s|&lt;img[^&gt;]*&gt;||gi;
		print OUT qq{&lt;li&gt;&lt;a name="$id" href="$file"&gt;$_&lt;/a&gt;\n&lt;ul&gt;\n};
		last;
	    }
	    while (&lt;FILE&gt;) {
		chomp;
		next  unless m|&lt;h3|i;
		($id) = m|name="(.*?)"|i;
		s|&lt;/?h\d.*?&gt;||gi; s|&lt;/?a.*?&gt;||gi;
		s|&lt;/?b&gt;||gi;
		s|&lt;img[^&gt;]*&gt;||gi;
		print OUT qq{&lt;li&gt;&lt;a name="$id" href="$file#$id"&gt;$_&lt;/a&gt;&lt;/li&gt;\n};
	    }
	    print OUT "&lt;/ul&gt;\n&lt;/ul&gt;\n";
	    close FILE;
	}
	print OUT "&lt;!--X-TOC-End--&gt;\n";
    }
}
close IN;
close OUT;
unlink "$tocfile.$$";

exit 0;
</pre></body></html>