Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A new css specific to simgrid (quite empty for now)
[simgrid.git] / tools / doxygen / doxygen_postprocesser.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 my %debug;
6 $debug{'parse'} = 0; # show how we parse the module tree
7 $debug{'input'} = 0; # display the resulting tree
8 $debug{'rename'}= 0; # do not overwrite the files (allows several debuging runs without rerunning doxygen)
9
10 ###
11 ### Get the module definitions
12 ###
13
14 open IN, "html/modules.html" || die "Cannot parse html/modules.html. Did you really run doxygen?\n";
15
16 # pass headers
17 while (<IN>) {
18   last if /group__SimGrid__API.html/;
19 }
20
21 # Parse the tree
22 my $top;
23 my $current;
24 my $entry;
25
26 $current->{'label'}="ROOT";
27 push @{$top->{'down'}},$current;
28 $current=$top;
29
30 print "Push $current as child of $top\n" if $debug{'parse'};
31
32 while (<IN>) {
33   if (/<ul>/) {
34     print "DOWN: $current -> " if $debug{'parse'};
35     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
36     print "$current\n" if $debug{'parse'};
37     next;
38   }
39   if (/<\/ul>/) {
40     $current = $current->{'up'};
41     print "UP\n" if $debug{'parse'};
42     next;
43   }
44   if (/<p>/) {
45     last;
46   }
47   
48   m|href="([^"]*)">([^<]*)</a>|; #"
49   
50   $entry = {};
51   $entry->{'file'} = $1;  
52   $entry->{'label'} = $2;
53   $entry->{'up'} = $current;
54   push @{$current->{'down'}},$entry;
55   print "Push $1 $2 as child of $current\n" if $debug{'parse'};
56 }
57 close IN;
58
59 # Check each file for extra information (short name, extra childs)
60 sub extra_info {
61   my $current=shift;
62
63   if (defined($current->{'file'})) {
64     open IN, "html/$current->{'file'}";
65     while (<IN>) {
66       if (/DOXYGEN_NAVBAR_LABEL/) {
67         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
68           $current->{'label'}=$1;
69         } else {
70           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
71         }
72       }
73       if (/DOXYGEN_NAVBAR_CHILD/) {
74         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
75           $entry = {};
76           $entry->{'label'} = $1;
77           $entry->{'file'} = $2;
78           chomp($entry->{'file'});
79           $entry->{'up'} = $current;
80           push @{$current->{'down'}},$entry;
81         } else {
82           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
83         }
84       }
85     }
86   }
87   
88   foreach my $entry (@{$current->{'down'}}) {
89     extra_info($entry);
90   }  
91 }
92 extra_info($top);
93
94 ## debug function
95 sub display {
96   my $current=shift;
97   my $level=shift;
98   print "  " x $level;
99   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
100   foreach my $entry (@{$current->{'down'}}) {
101     display($entry,$level+1);
102   }
103 }
104
105 display($top,0) if $debug{'input'};
106
107 ###
108 ### Generate the navbar
109 ###
110
111 # the root deserves some special handling
112 open IN,"html/modules.html" || die;
113 open OUT,">html/modules.new.html" || die;
114 my $line;
115 while ($line = <IN>) {
116   last if $line =~ /<h1>SimGrid Modules</;
117   print OUT $line;
118 }
119
120 print OUT "<div class=\"tabs\">\n  <ul>\n";
121 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
122   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
123 }
124 print OUT "  </ul></div>\n";
125 print OUT $line;
126 while (<IN>) {
127   print OUT $_;
128 }
129
130 close OUT;
131 close IN;
132 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
133
134 # Operate the recursion
135 sub handle_page {
136   my $current=shift;
137   my $level=shift;
138
139   # we generate the tabs bottom up begining from where we are in the tree
140   # and display them top down, as it should in a file
141   my @tabs = ();
142
143   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
144 #    print "handle $current->{'file'}, at level $level\n";
145     # generate the tabs
146     my $iterator = $current;
147     my $lvl_it=$level;
148     while ($lvl_it >= 0) {
149       my $father = $iterator->{'up'};
150       $tabs[$lvl_it] = "<div class=\"tabs\">\n  <ul>\n";
151       foreach my $bro (@{$father->{'down'}}) {
152         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" id=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
153       }
154       $tabs[$lvl_it] .= "  </ul></div>\n";
155       $iterator = $father;
156       $lvl_it--;
157     }
158     if (defined $current->{'down'}) { # there's some kid. Display them too
159       $tabs[$level+1] = "<div class=\"tabs\">\n  <ul>\n";
160       foreach my $kid (@{$current->{'down'}}) {
161         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
162       }
163       $tabs[$level+1] .= "  </ul></div>\n";      
164     }
165     
166     # put them in place
167     open FROM,"html/$current->{'file'}" || die;
168     my $newname="html/$current->{'file'}";
169     $newname =~ s/.html/.new.html/;
170     open TO,">$newname" || die;
171     while (<FROM>) {
172       # add "current" to the module API granfather page
173       s|<li><a href="modules.html"><span>Modules API</span></a></li>|<li id="current"><a href="modules.html"><span>Modules API</span></a></li>|;
174       
175       print TO $_;
176       last if m|</ul></div>|;
177     }
178     foreach (@tabs) {
179       print TO $_;
180     }
181     while (<FROM>) {
182       print TO $_;
183     }    
184     close FROM;
185     close TO;
186     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
187   } 
188   
189   # recurse on childs
190   foreach my $entry (@{$current->{'down'}}) {
191     handle_page($entry,$level+1);
192   }
193 }
194
195 handle_page($top,-2);# skip roots (we have 2 roots) in level counting