Logo AND Algorithmique Numérique Distribuée

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