Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c5b2b46bb81a51a92b489a7f47756895e936595f
[simgrid.git] / tools / doxygen / toc_create.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 ($#ARGV >= 1) or die "Usage: toc_create.pl <input-doc-file>+";
6
7 sub handle_file {
8   my $infile = shift;
9   open FILE,$infile;
10
11   my(@toc);
12   my($level,$label,$name);
13
14   while(my $line=<FILE>) {
15     chomp $line;
16     if($line=~/\\section\s*(\S\S*)\s*(.*)$/) {
17 #       print "$line\n";
18         $label = $1;
19         $name = $2;
20         $level=0;
21 #       print "$label : $name\n";
22         push @toc,[$level,$label,$name];
23     } elsif($line=~/\\subsection\s*(\S\S*)\s*(.*)$/) {
24 #       print "$line\n";
25         $label = $1;
26         $name = $2;
27         $level=1;
28 #       print "\t$label : $name\n";
29         push @toc,[$level,$label,$name];
30     } elsif($line=~/\\subsubsection\s*(\S\S*)\s*(.*)$/) {
31 #       print "$line\n";
32         $label = $1;
33         $name = $2;
34         $level=2;
35 #       print "\t\t$label : $name\n";
36         push @toc,[$level,$label,$name];
37     }
38   }
39   close FILE;
40
41   my $outfile = ".$infile.toc";
42   $outfile =~ s|\.\./||g;
43   $outfile =~ s|/|_|g;
44   open OUTPUT,"> $outfile";
45   my($current_level)=-1;
46   my($entry);
47   print OUTPUT "<!-- Automatically generated table of contents --!>\n";
48   print OUTPUT "<div class=\"toc\">\n";
49   print OUTPUT "<div class=\"tocTitle\">Table of content</div>\n";
50   foreach $entry (@toc) {
51       ($level,$label,$name) = @$entry;
52
53       while($current_level<$level) {
54           print OUTPUT "<ol type=\"1\">\n";
55           $current_level++;
56       } 
57       while($current_level>$level) {
58           print OUTPUT "</ol>\n";
59           $current_level--;
60       }
61       foreach (1..$current_level) {
62           print OUTPUT "\t";
63       }
64       print OUTPUT "<li> <a href=\"#$label\">$name</a>\n";
65   }
66
67   while($current_level>-1) {
68       print OUTPUT "</ol>\n";
69       $current_level--;
70   }
71   print OUTPUT "</div>\n";
72   print OUTPUT "<!-- End of automatically generated table of contents --!>\n";
73 } # sub handle_file
74
75
76 map { handle_file($_) } @ARGV;