Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / doc / MHonArc / faq / _helper / addtoc-i.pl
CommitLineData
86530b38
AT
1#!/usr/local/bin/perl
2#
3# $Date: 1998/02/18 16:37:07 $
4
5my($tocfile, $toctxt);
6
7foreach $tocfile (@ARGV) {
8 if (! -w $tocfile) {
9 warn qq/Warning: "$tocfile" is not writable\n/;
10 next;
11 }
12 system("/bin/cp $tocfile $tocfile.$$");
13 open(IN, "$tocfile.$$") or die "Unable to open $tocfile\n";
14 open(OUT, ">$tocfile") or die "Unable to create $tocfile\n";
15
16 $toctxt = "";
17 while (<IN>) {
18 chomp;
19 next unless m|<h3|i;
20 ($id) = m|name="([^"]+)"|i;
21 s|</?h\d.*?>||gi;
22 s|</?a.*?>||gi;
23 s|</?b>||gi;
24 s|<img[^>]*>||gi;
25 $toctxt .= qq{<li><a href="#$id">$_</a></li>\n};
26 }
27 seek IN, 0, 0;
28 while (<IN>) {
29 print OUT $_;
30 if (/<!--X-TOC-Start-->/) {
31 while (<IN>) {
32 last if (/<!--X-TOC-End-->/);
33 }
34 print OUT "<ul>\n", $toctxt, "</ul>\n",
35 "<!--X-TOC-End-->\n";
36 }
37 }
38
39 close IN;
40 close OUT;
41 unlink "$tocfile.$$";
42}
43
44exit 0;