Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix compilation warning for unused variables
[simgrid.git] / tools / doxygen / doxygen_postprocesser.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 # Add here the pages of the documentation generated by a @page doxygen macro
6 my @extra_files = qw(html/index.html html/pages.html html/modules.html html/annotated.html html/functions.html 
7                                          html/functions_vars.html index.php 
8                      html/GRAS_tut.html html/tracing.html html/platform.html html/install.html html/bindings.html
9                      html/options.html html/use.html html/pls.html html/FAQ.html);
10
11 # GRAS tutorial
12 map {push @extra_files, "html/GRAS_tut_$_.html"} qw (intro 
13                                                      tour tour_install tour_setup tour_simpleexchange tour_args tour_callbacks tour_globals 
14                                                           tour_logs tour_timers tour_exceptions tour_simpledata tour_rpc tour_explicitwait
15                                                           tour_message_recaping tour_staticstruct tour_pointers tour_dynar 
16                                                           tour_manualdatadef tour_exchangecb);
17
18 # GRAS examples
19 map {push @extra_files, "html/GRAS_ex_$_.html"} qw (ping mmrpc token timer);
20
21 my %debug;
22 $debug{'parse'} = 0; # show how we parse the module tree
23 $debug{'input'} = 0; # display the resulting tree
24 $debug{'handle'}= 0; # Be verbose on the post-processing
25 $debug{'rename'}= 0; # do not overwrite the files (allows several debuging runs without rerunning doxygen)
26
27 my @allfiles;
28 ###
29 ### Get the module definitions
30 ###
31
32 open IN, "html/modules.html" || die "Cannot parse html/modules.html. Did you really run doxygen?\n";
33
34 # pass headers
35 while (<IN>) {
36   last if /group__SimGrid__API.html/;
37 }
38
39 # Parse the tree
40 my $top;
41 my $current;
42 my $entry;
43
44 # $current->{'label'}="ROOT";
45 # push @{$top->{'down'}},$current;
46 # print "Push $current '".($current->{'label'})."' as child of $top '".($top->{'label'})."'\n" if $debug{'parse'};
47 # $current=$top;
48 $top->{'label'}="ROOT";
49 print "Create ROOT $top\n" if $debug{'parse'};
50 $current=$top;
51
52
53 # Read the whole data to postprocess it a bit
54 my $in;
55 while (<IN>) {
56     $in .= $_;
57 }
58 $in =~ s/<ul>/\n<ul>\n/sg;
59 foreach $_ (split(/\n/,$in)) {
60     next unless length($_);
61     next if ($_ =~ m|^</li>$|);
62     print "  Seen '$_'\n" if $debug{'parse'};
63   if (/<ul>/) {
64     print "DOWN: $current '$current->{'label'}' -> " if $debug{'parse'};
65     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
66     print "$current '$current->{'label'}'\n" if $debug{'parse'};
67     next;
68   }
69   if (/<\/ul>/) {
70     $current = $current->{'up'};
71     print "UP to $current '$current->{'label'}'\n" if $debug{'parse'};
72     next;
73   }
74   if (/<p>/) {
75     last;
76   }
77   
78   m|href="([^"]*)">([^<]*)</a>|; #"
79   
80   $entry = {};
81   $entry->{'file'} = $1;  
82   $entry->{'label'} = $2;
83   $entry->{'up'} = $current;
84   push @{$current->{'down'}},$entry;
85   print "Push file:$1 label:'$2' as child of $current '$current->{'label'}'\n" if $debug{'parse'};
86   push @allfiles,"html/$1";
87 }
88 close IN;
89
90 # Check each file for extra information (short name, extra childs)
91 sub extra_info {
92   my $current=shift;
93
94   if (defined($current->{'file'})) {
95     open IN, "html/$current->{'file'}";
96     while (<IN>) {
97       if (/DOXYGEN_NAVBAR_LABEL/) {
98         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
99           print "Extra info from $current->{'file'}: label=$1, not $current->{'label'}\n" if $debug{'parse'};
100           $current->{'label'}=$1;
101         } else {
102           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
103         }
104       }
105       if (/DOXYGEN_NAVBAR_CHILD/) {
106         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
107           $entry = {};
108           $entry->{'label'} = $1;
109           $entry->{'file'} = $2;
110           chomp($entry->{'file'});
111           $entry->{'up'} = $current;
112           push @{$current->{'down'}},$entry;
113           print "Extra info from $current->{'file'}: New child $entry->{'label'}=$entry->{'file'}\n"  if $debug{'parse'};
114         } else {
115           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
116         }
117       }
118     }
119   }
120   
121   foreach my $entry (@{$current->{'down'}}) {
122     extra_info($entry);
123   }  
124 }
125 extra_info($top);
126
127 ## debug function
128 sub display {
129   my $current=shift;
130   my $level=shift;
131   print "  " x $level;
132   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
133   foreach my $entry (@{$current->{'down'}}) {
134     display($entry,$level+1);
135   }
136 }
137
138 display($top,0) if $debug{'input'};
139
140 ###
141 ### Generate the navbar
142 ###
143
144 # the root deserves some special handling
145 open IN,"html/modules.html" || die;
146 open OUT,">html/modules.new.html" || die;
147 my $line;
148 while ($line = <IN>) {
149   last if $line =~ /<h1>SimGrid Modules</;
150   print OUT $line;
151 }
152
153 print OUT "<div class=\"tabs\">\n  <ul class=\"tablist\">\n";
154 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
155   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
156 }
157 print OUT "  </ul></div>\n";
158 print OUT $line;
159 while (<IN>) {
160   print OUT $_;
161 }
162
163 close OUT;
164 close IN;
165 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
166
167 # Operate the recursion
168 sub handle_page {
169   my $current=shift;
170   my $level=shift;
171
172   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
173     
174   # we generate the tabs bottom up begining from where we are in the tree
175   # and display them top down, as it should in a file
176   my @tabs = ();
177   my $found_div_tabs=0;
178   
179   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
180 #    print "handle $current->{'file'}, at level $level\n";
181     # generate the tabs
182     my $iterator = $current;
183     my $lvl_it=$level;
184     while ($lvl_it >= 0) {
185       my $father = $iterator->{'up'};
186       $tabs[$lvl_it] = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
187       foreach my $bro (@{$father->{'down'}}) {
188         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
189       }
190       $tabs[$lvl_it] .= "  </ul></div>\n";
191       $iterator = $father;
192       $lvl_it--;
193     }
194     if (defined $current->{'down'}) { # there's some kid. Display them too
195       $tabs[$level+1] = "<div class=\"tabs2\">\n  <ul class=\"tablist\">\n";
196       foreach my $kid (@{$current->{'down'}}) {
197         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
198       }
199       $tabs[$level+1] .= "  </ul></div>\n";      
200     }
201     
202     # put them in place
203     open FROM,"html/$current->{'file'}" || die;
204     my $newname="html/$current->{'file'}";
205     $newname =~ s/.html/.handlepage.html/;
206     open TO,">$newname" || die;
207 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
208     while (<FROM>) {
209 #      print "--Read  $_";
210       # add "current" to the module API granfather page
211       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
212 #      print "++Write $_";
213           $found_div_tabs=1 if m/div.*class="tabs"/;    
214       print TO "$_";
215       last if ((m|</div>|)&&($found_div_tabs));
216     }
217     
218     print TO "\n<!-- POST-PROCESSED TABS -->\n";
219              
220     foreach (@tabs) {
221 #      print "TAB: $_";
222       print TO "$_";
223     }
224     print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
225       
226     if ($current->{'file'} =~ m/^class/) {
227           while (<FROM>) {
228                 last if (m|</div>|);
229           }
230       print TO "$_";    
231     }
232     while (<FROM>) {
233       if (m/POST-PROCESSED TABS/) {
234             while (<FROM>) {
235               last if (m/END OF POST-PROCESSED TABS/);
236             }
237             next;
238       }
239
240       if (m/The documentation for/) {
241             while (<FROM>) {
242               last if (m/<p>/);
243             }
244       }
245       print TO "$_";
246     }
247     close FROM;
248     close TO;
249     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
250   } 
251   
252   # recurse on childs
253   foreach my $entry (@{$current->{'down'}}) {
254     handle_page($entry,$level+1);
255   }
256 }
257
258 ###
259 ### Launch the modules navbar reworking
260 ###
261 handle_page($top,-1);# skip roots (we have 2 roots) in level counting
262
263 ###
264 ### Add the modules navbar reworking to the modules.html file
265 ###
266 sub add_tabs_to_module_html {
267   my $found_div_tabs=0;
268   my $module_tabs = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
269   foreach my $entry (@{$top->{'down'}}) {
270       $module_tabs .= "  <li> <a href=\"$entry->{'file'}\"><span>$entry->{'label'}</span></a></li>\n";
271   }
272   $module_tabs .= "  </ul></div>\n";      
273   
274   my $oldname = "html/modules.html";
275   open FROM,$oldname || die;
276   my $newname=$oldname;
277   $newname =~ s/.html/.handlepage.html/;
278   open TO,">$newname" || die;
279   while (<FROM>) {
280     $found_div_tabs=1 if m/div.*class="tabs"/;  
281         print TO "$_";
282         last if ((m|</div>|)&&($found_div_tabs));
283   }
284   
285   print TO "\n<!-- POST-PROCESSED TABS -->\n";
286   print TO $module_tabs;
287   print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
288
289   while (<FROM>) {
290         print TO "$_";
291   }  
292   close FROM;
293   close TO;
294   rename($newname, $oldname) unless $debug{'rename'};
295   
296   # die;
297 }   
298
299 add_tabs_to_module_html;
300
301 ###
302 ### Post-processsing common to all pages
303 ###
304 map {push @allfiles,$_} @extra_files;
305 print "All files: ".(join(", ",@allfiles))."\n" if $debug{'parse'};
306 my $tabs;
307
308 foreach my $file (@allfiles) {
309     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
310         
311     open FROM,"$file" || die;
312     my $outfile = "$file";
313     $outfile =~ s/.(html|php)$/.new.$1/;
314     open TO,">$outfile" || die;
315 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
316     while (<FROM>) {
317       # Add the simgrid css, just in case
318       print TO '<link href="simgrid.css" rel="stylesheet" type="text/css">'."\n"
319         if (m|</head>|);
320
321           if($tabs){
322                   if($file =~ /^html\/index\..*/){
323                         $_ =~ s/<li class="current">/<li>/g;
324                         $_ =~ s/<li><a href="index.html">/<li class="current"><a href="index.html">/g;
325                   }               
326                   $_ =~ s/<li class="current"><a href="pages.html">/<li><a href="pages.html">/g;
327                   
328                   if($file =~ /^html\/pages\..*/){
329                         $_ =~ s/<li><a href="pages.html">/<li class="current"><a href="pages.html">/g;
330                   }
331           }
332           
333           if($file =~ /^html\/publis.*/){
334                         $_ =~ s/<div class="header">/<div>/g;
335                         $_ =~ s/<div class="headertitle">/<div>/g;
336          }
337         
338           # Add the FAQ PUBLIS PEOPLE HISTORY and CONTRIB to the top navbar.
339       if( $_ =~ /<div.*class="tabs">/){
340         $tabs = 1;
341       }
342       if( $_ =~ /<\/div>/){
343         $tabs = 0;
344       }
345       if( $_ =~ /<\/ul>/ && $tabs){
346                 my $tmp_buff="";
347                 $tmp_buff .= '      <li><a href="use.html"><span>Using SimGrid</span></a></li>'."\n";
348                 $tmp_buff .= '      <li><a href="http://gforge.inria.fr/projects/simgrid"><span>Forge</span></a></li>'."\n";
349                 $tmp_buff .= '      <li><a href="http://simgrid.gforge.inria.fr/"><span>Website</span></a></li>'."\n";
350                 $tmp_buff .= '      <li><a href="pages.html"><span>Documentation&nbsp;index</span></a></li>'."\n";
351                 $tmp_buff .= '      <li><a href="FAQ.html"><span>FAQ</span></a></li>'."\n";
352                 $tmp_buff .= $_;
353                 $tabs = 0;
354
355               # Rework the navbar and add menu for use.html
356               # Fix the current "button" of buggy Doxygen tabs  
357               if($file =~ /^html\/use.*/
358               || $file =~ /^html\/install.*/
359               || $file =~ /^html\/options.*/
360               || $file =~ /^html\/tracing.*/ 
361               || $file =~ /^html\/platform.*/ 
362               || $file =~ /^html\/bindings.*/
363               || $file =~ /^html\/pls.*/
364               || $file =~ /^html\/modules.*/
365               || $file =~ /^html\/annotated.*/
366               || $file =~ /^html\/group__.*/
367               || $file =~ /^html\/functions.*/
368               || $file =~ /^html\/GRAS_tut_tour_.*/)
369               {
370                                 $tmp_buff .= '      <div class="tabs_group_use">'."\n";
371                                 $tmp_buff .= '          <ul class="tablist">'."\n";
372                                 $tmp_buff .= '          <li><a href="install.html"><span>Installing SimGrid</span></a></li>'."\n";
373                                 $tmp_buff .= '          <li><a href="modules.html"><span>Modules&#160;API</span></a></li>'."\n";
374                                 $tmp_buff .= '          <li><a href="options.html"><span>Options & configurations</span></a></li>'."\n";
375                                 $tmp_buff .= '          <li><a href="platform.html"><span>Platform Description</span></a></li>'."\n";
376                                 $tmp_buff .= '          <li><a href="tracing.html"><span>Tracing Simulations</span></a></li>'."\n";
377                                 $tmp_buff .= '          <li><a href="bindings.html"><span>Bindings</span></a></li>'."\n";
378                                 $tmp_buff .= '          <li><a href="pls.html"><span>Packet-Level Simulation</span></a></li>'."\n";
379                                 $tmp_buff .= '          </ul></div>'."\n";
380                                 $tmp_buff .= '      </div>'."\n";
381                                 
382                                 my $filename = $file;
383                         $filename =~ s/html\///g;
384                         $filename =~ s/\.html//g;
385                         $filename =~ s/publis_.*/publis/g;
386                         $tmp_buff =~ s/<li class="current">/<li>/g;
387                         $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;
388                         $tmp_buff =~ s/<li><a href="use.html">/<li class="current"><a href="use.html">/g; 
389                                 
390               }
391         
392               # Rework the navbar
393               # Fix the current "button" of buggy Doxygen tabs   
394               if($file =~ /^html\/pages.*/
395               || $file =~ /^html\/FAQ.*/)
396               {
397                       my $filename = $file;
398                       $filename =~ s/html\///g;
399                       $filename =~ s/\.html//g;
400                       $tmp_buff =~ s/<li class="current">/<li>/g;
401                       $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;     
402               }
403               if($file =~ /^html\/group__.*/
404               || $file =~ /^html\/GRAS_tut_tour_.*/)
405               {
406                 $tmp_buff =~ s/<li><a href="modules.html">/<li class="current"><a href="modules.html">/g;
407               }
408               if($file =~ /^html\/functions.*/)
409               {
410                 $tmp_buff =~ s/<li><a href="annotated.html">/<li class="current"><a href="annotated.html">/g;
411               }
412               
413               print TO $tmp_buff;             
414               next;
415     }
416       s|<span>Modules</span>|<span>Modules&#160;API</span>|g;
417       s|<li.*><a href="pages.html"><span>Related&#160;Pages</span></a></li>\n||g;
418       s|<li class="current"><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
419       s|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>\n||g;
420       if($file =~ /^html\/group__.*/)
421       {
422         s|<li><a href="use.html">|<li class="current"><a href="use.html">|g;
423         s|<li><a href="modules.html"><span>Modules&#160;API</span></a></li>\n|<li class="current"><a href="modules.html"><span>Modules&#160;API</span></a></li>\n|g;
424       }
425       else
426       {
427         s|<li><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
428       }
429       s|<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;    
430       s|<li class="current"><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
431       s|Related Pages<|Documentation&nbsp;index<|g;
432                                                                                            
433       print TO $_;
434     }
435     close FROM;
436     close TO;
437     rename("$outfile", "$file") unless $debug{'rename'};
438 }
439
440
441